7.4 Test Assert Methods

     

7.4 Test Assert Methods

CppUnit provides several variations on the basic assert method. The assert methods are implemented as macros. The advantage of using macros to implement assert methods is that they enable the compiler preprocessor to record the source code location of each assert, which is otherwise hard to do in C.

As in other xUnits, some of the asserts have variants that take a descriptive message argument. The message is reported if the test fails. Examples of these variants are shown in the following list:


CPPUNIT_ASSERT(condition)

CPPUNIT_ASSERT_MESSAGE(message,condition)

Test that passes if condition is true .


CPPUNIT_FAIL(message)

Test that always fails.


CPPUNIT_ASSERT_EQUAL(expected,actual)

CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual)

Test that passes if expected and actual are equal. It supports arguments of most common data types and std::string .


CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta)

Test that passes if expected and actual are equal within a tolerance of delta . The arguments are of type double .



Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net