CppUnit is an open source testing tool that comes from the Java version of JUnit. Unit testing plays a very important role in the theory of extreme programming. Even without extreme programming, each software engineer should write a test program, prepare test data, and test its own written software module to run.
CppUnit can be used to test multiple software modules at the same time, and shows how many successes and how many failed. There is a command-line operation, VC written GUI program interface, also has QT GUI program interface. The following is the VC operating interface.
If you want to use CppUnit for software testing, you can go to the CppUnit on the Sourceforge above the site to download the original code, which has a sample program.
We can start from the CPPUNIT-1.10.2/EXAMPLES/MSVC6/CPPUNITTESTAPP/CPPUNITTESTAPP.DSW transformation, all compiled, will be the original cppunit, Dsplugin, Testrunner Several project deletions, leaving only Cppunittestapp project. In VC's File View, remove the original DLL dependencies,tests. Then add your own test program.
Test C + + code must be added to this Project, if you use C + + Builder can only use the version of that command line. If there are failed test units, then which test units are displayed.
A generic test unit that writes a cppunit_ns::testcase subclass that writes one or more testxxx functions. Invoke the formal code in TESTXXX:
void Testxxx () {
int result = Myfun (1,2);
Cppunit_assert_equal (result,7);
result = Myfun (10,70);
Cppunit_assert_equal (result,9);
}
Each test function calculates a testing base element. If all the assert in it succeeds, the test function is passed.
Typically, the data used for testing is not written in the source code, but in XML or INI or other files. The benefit is to change the test data when testing, without recompiling the program to facilitate testing.
A more general approach is to write a basetestcase class that handles data reading and output, and other test cells inherit from this basetestcase.
Rather than JUnit, the CppUnit is that new test programs need to be added to test project, and for many people at the same time writing test units, everyone is waiting for someone else to revise the test project to get it done, not too good. In contrast, a Java test program may not need any project files. The workaround is to split test project into multiple child project, but you won't be able to run all the tests in one Test program.
The advantage of CppUnit is that it runs faster.