#include#include class ExampleTestCase : public CppUnit::TestCase { CPPUNIT_TEST_SUITE( ExampleTestCase ); CPPUNIT_TEST( testMethod ); CPPUNIT_TEST_SUITE_END(); public: void testMethod() { int num = 3; CPPUNIT_ASSERT( num == 3 ); } }; int main() { CppUnit::TextUi::TestRunner runner; runner.addTest( ExampleTestCase::suite() ); runner.run(); return 0; }
#includeThis example creates another test case using the CppUnit framework and adds it to the TestRunner. The test case contains two test methods that check if variables equal certain values, one using CPPUNIT_ASSERT and the other using CPPUNIT_ASSERT_EQUAL. The TestRunner executes both tests and prints the results to the console. Both examples use the CppUnit framework and the TestRunner is part of the CppUnit package library.#include class AnotherTestCase : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( AnotherTestCase ); CPPUNIT_TEST( testMethod1 ); CPPUNIT_TEST( testMethod2 ); CPPUNIT_TEST_SUITE_END(); public: void testMethod1() { int num = 5; CPPUNIT_ASSERT( num == 5 ); } void testMethod2() { int num = 10; CPPUNIT_ASSERT_EQUAL( num, 10 ); } }; int main() { CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); CppUnit::TextUi::TestRunner runner; runner.addTest( registry.makeTest() ); runner.run(); return 0; }