Thursday, October 22, 2009

7.4 Test Assert Methods











 < Day Day Up > 







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.

























     < Day Day Up > 



    No comments:

    Post a Comment