CppSpec

Software Screenshot:
CppSpec
Software Details:
Version: 0.4
Upload Date: 3 Jun 15
Developer: Timo Puronen
Distribution Type: Freeware
Downloads: 8

Rating: nan/5 (Total Votes: 0)

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.

Similar Software

Comments to CppSpec

Comments not found
Add Comment
Turn on images!