C ++ unit test tool cppunittest

Source: Internet
Author: User

Cppunit is an open-source testing tool, derived from the Java version of JUnit. Unit testing plays an important role in extreme programming theory. Even if no eXtreme Programming method is used, each software engineer should write the test program, prepare the test data, and test that the software module written by himself can run.

Cppunit can be used to test multiple software modules at the same time and display the number of successes and failures. Command Line running, Gui written by VC, and GUI of QT. The following is the VC running interface.

If you want to use cppunit for software testing, you can download the original code from the cppunit website on SourceForge, which contains the sample program.

We can start from the cppunit-1.10.2/examples/msvc6/cppunittestapp. DSW transformation, after all the compilation, the original cppunit, dsplugin, testrunner several projects are deleted, leaving only cppunittestapp project. Delete the original DLL dependencies and tests in the file view of VC. Then add your own test program.

All the tested C ++ code must be added to this project. If you use C ++ builder, you can only use the command line version. If a failed test unit exists, the unit is displayed.

For a general test unit, write a subclass of cppunit_ns: testcase, which writes one or more testxxx functions. Call the official 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 is considered as a basic test element. If all the assert operations in it are successful, the test function will pass.

Generally, the data used for testing is not written in the source code, but in XML, INI, or other files. The advantage is that you do not need to re-compile the program to change the test data during the test.

A general method is to write a basetestcase class, which processes the data reading and output, and other test units are inherited from this basetestcase.

Compared with JUnit, cppunit is inconvenient because the new test program needs to be added to the test project, everyone is waiting for others to finish modifying the test project. Relatively speaking, Java testing programs do not need any project files. The work und is to split the test project into multiple sub-projects, but thus you cannot run all the tests in a test program.

Cppunit is faster.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.