Tuesday 12th of August 2008 21:24
One thing I don’t think I mentioned in the last post is that in the ClassNameTest.cpp file we need to register the test suite using a macro:
CPPUNIT_TEST_SUITE_REGISTRATION( ClassNameTest );
which registers the test suite so that it will be run.
The assertions which are possible include (lifted directly from the api documentation at the CppUnit sourceforge page):
Aserts that condition is true.
Asert condition is true, and display message on failure.
Fails with the message.
Checks that both values are equal.
CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual)
As above but fails with the message.
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta)
Checks that expected is within delta of actual (delta should actually be epsilon!)
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message, expected, actual, delta)
As above but fails with message.
Asserts that the given expression throws an exception of the type given.
CPPUNIT_ASSERT_THROW_MESSAGE(message, expression, ExceptionType)
As above but with a message on failure.
This is the opposite of the above the expression does NOT throw an exception.
If it does throw an exception then we fail with the given message.
Assert that a CPPUNIT assertion will fail.
As above but with a message if the assertion passes.
Assert that a CPPUNIT assertion will pass.
As above but displays he message of it fails.
I think there are more possible assertions as the CppUnit Cookbook uses a statement in setting up the tests which checks for a given exception type being thrown.
Enough for today.