CppSpec 0.4

CppSpec is a behavior driven development (BDD) framework for C++.
CppSpec is a behavior driven development (BDD) framework for C++. Behavior Driven Development is a refinement of TDD which turns the focus from writing the tests to the process of defining the behavior of the software using tests.

Using CppSpec

To define behavior of your class you need to create a specifications for different states of your class. Specification is created by deriving from CppSpec::Specification class. Expectations for the behavior are written using specify method.

Basic validation

specify(should.be.empty());
specify(not should.be.empty());
specify(context().count(), should.equal(1));

Exception handling

Exceptions are tested by defining a executable block which is expected to throw an exceptions. A block is defined by deriving from Block and implementing run() method. The most convenient way to do this is to use local, anonymous classes. For example:

struct : Block {
void run() {
context().methodWhichThrowsException();
}
} block;

specify(block, should.raise.exception());
specify(block, should.raise.exception("Division by zero")); // throws std::string with content "Division by zero"

Containers

If the context implements iterator interface, you can specify that context should contain either unique items or sequences using contain keyword.

specify(should.have.element("key"));
specify(should.have.elements(sequence.begin(), sequence.end()));

Regular expressions

specify(context().asString(), should.contain(pattern));
specify(context().asString(), should.match(pattern));

Compiling CppSpec

CppSpec is compiled using cmake (www.cmake.org) and native C++ toolchain. Pre-requisites for CppSpec are Boost headers and CppUTest. CppUTest is used for tests of CppSpec itself. If you don't have it and you're not interested in executing the tests you can remove test directory from main level CMakeLists.txt.

If CMake can't find the required libraries, you can either edit manually CMakeCache.txt and add the locations or use environment variables which are used by CMake to search for the dependencies. Please refer to CMake documentation for more information (http://www.cmake.org/).

What's New in This Release:

· Greatly improved messages for failures.
· A CUTE logger for usage with the CUTE Eclipse plugin.
· Specification execution time measurements have been improved.
· Build fixes for Visual C++. install and CPack targets to enable the make install target and creation of binary distribution packages.
· Bugfixes.

last updated on:
August 8th, 2008, 22:28 GMT
price:
FREE!
homepage:
www.laughingpanda.org
license type:
The Apache License 2.0 
developed by:
Timo Puronen
category:
ROOT \ Programming \ Quality Assurance and Testing
CppSpec
Download Button

In a hurry? Add it to your Download Basket!

user rating 17

2.8/5
 

0/5

Rate it!

Add your review!

SUBMIT