[Solved] How to create a test run/plan for a C++ Program? [closed]


For unit tests, you would typically use a unit-test framework such as CppUnit:

  • For each class, you create a series of test;
  • For each method to be tested, you develop a dedicated test;
  • Each test verifies some assertions using functions or macros such as CPPUNIT_ASSERT, CPPUNIT_FAIL, CPPUNIT_ASSERT_THROW;
  • It’s often useful to make the tester class friend to the tested class.

Here is an example for testing your constructors:

void DateUnitTest::ConstructorTests
{
    // Test default-ctor
    { 
        Date date;
        CPPUNIT_ASSERT ( date.day   == 0 );
        CPPUNIT_ASSERT ( date.month == 0 );
        CPPUNIT_ASSERT ( date.year  == 0 );
    }

    // Test ctor with args
    { 
        Date date(31,12,2015);
        CPPUNIT_ASSERT ( date.day   == 31 );
        CPPUNIT_ASSERT ( date.month == 12 );
        CPPUNIT_ASSERT ( date.year  == 2015 );
    }
}

3

solved How to create a test run/plan for a C++ Program? [closed]