C ++ unit test tool CPPUNITTEST

xiaoxiao2021-03-06  65

CPPUnit is an open source test tool that comes from Junit, JAVA. Unit tests have a very important role in extreme programming theory. Each software engineer should write a test program even if it is not used, each software engineer should write the test data to test the software modules you write.

CPPUnit can be used to test multiple software modules simultaneously, and how many success is displayed, how much failed. There is a command line to run, the VC written in the GUI program interface, also has the QT GUI program interface. The following is the VC run interface.

If you want to use CPPUnit to perform software test, you can download the original code in the website of the SourceForge on the website. There is a sample program.

We can transform from cppUnit-1.10.2 / exampleApp / cppUnittestapp.dsw, all compile, delete the original CPPUnit, DSPLUGIN, TESTRunner several Project, leaving only CPPUnitTestApp Project. The File View in the VC will delete the original DLL Dependencies, Tests. Then add your own test program.

The test C code must be added to this Project, and if you use C Builder, you can only use the version of the command line. If there is a failed test unit, what test unit is displayed.

A general test unit, write a subclass of CPPUnit_ns :: Testcase, write one or more Testxxx functions. Call 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 test basic element. If all Asserts inside it are successful, this TEST function is only passed.

In general, the data used is generally not written in the source code, but written in XML or INI or other files. This benefit is to change the test data when testing, which is easy to test.

The relatively common method is to write a BaseTestCase class, handle data read, output, and other test units are inherited from this basestCase.

Compared with JUnit, the inconvenient CPPUnit is that the new test program needs to be added to test Project. For many people while writing test units, everyone is waiting for others to modify the test Project to do, not very good. Relatively, the Java test program does not require any Project files. The way the way is to split the test Project into multiple projects, but this will not run all tests in a test program.

The benefits of CPPUnit are running faster.

转载请注明原文地址:https://www.9cbs.com/read-119125.html

New Post(0)