Structure of specificationsCppSpec suite consists of specifications. Specification specifies the behavior of the context in certain state. An example of a specification is an empty stack. Specifications have behaviors, e.g. empty stack should raise an exception when popped. In CppSpec specifications are classes derived from Specification class and behaviors are member methods of these classes. Writing specificationsThe expected behavior is specified in behaviors using specify method, for example:
The first example specifies that count() method of the context must return 0. The second example specifies that empty() method of the context must return true. This is a shorter form of the equivalent specification specify(context().empty(), should.equal(true)). Below are shown different kinds of specifications available in CppSpec. Basic validation
Exception handling Specifying that a method must throw an exception is done using invoking syntax:
Invoking takes an function pointer to a context member function and possible arguments as an argument. Either class or value of the expected exception if given as an argument for exception method. Containers If the context implements iterator interface, you can specify that context should contain either unique items or sequences using contain keyword.
Regular expressions
Executing specificationsAll specifications are compiled as executables which main function must call SpecRunner::runSpecifications. CppSpec has the following command line arguments:
Reporting CppSpec supports three logging formats:
By default JUnit reports are generated to the working directory unless --report-dir argument is used to specify another path. The reports are named after specifications. JUnit reports can be redirected to standard output by giving --no-logs argument. To use console reporting, -o console (or --output console) argument must be given when executing the specifications. For Eclipse integration run specification from Eclipse as CUTE test giving -o cute as an argument. |