Testcase
, For a single test case, define the parent class of the test class;
Testsuit
, A group of test cases, composed
Testcase
Composition;
Basic steps:
1
, Create a project, set
Rtti
And Multithreading
Lib
, Add the required
Lib
, Such as cppunitd. Lib testrunnerd. Lib
2
, Derived from cppunit: testcase test class cplustestcase; <cppunit/testcase. h>
<Cppunit/extensions/helpermacros. h>
<Cppunit/extensions/testfactoryregistry. h>
3
, Register in the cplustestcase Declaration
Testsuit
To add the testadd function to the cplustestcase
Testsuit
Medium:
Class
Cplustestcase: Public cppunit: testcase
{
Cppunit_test_suite (cplustestcase );
Cppunit_test (testadd );
//
Testadd is a custom test function.
Cppunit_test_suite_end ();
Public:
Cplustestcase (void );
//
The constructor is called in Runner. addtest instead of run.
()
Or when testing
~ Cplustestcase (void );
Void testadd (void );
};
4
, Register in the cplustestcase implementation file
Testsuit
, Indicates
Testsuit
Register cplustestcase
ABC
In this group;
Cppunit_test_suite_named_registration (cplustestcase,
"
ABC
");
5
, InProgramUse testrunner to add tests and execute tests at startup. <cppunit/UI/mfc/testrunner. h>, as shown in figure
(
<Cppunit/extensions/testfactoryregistry. h>
)
;
Cppunit: mfcui: testrunner
Runner;
Runner. addtest (cppunit: testfactoryregistry: getregistry ("
ABC
"). Maketest ());
// Add a test
Runner. Run (); // show
UI
Note:
1
,
cppunit
corresponding header file
#include
to be placed
# front of define new debug_new;
2
, Use the corresponding
Lib
Of
Debug
Or
Release
Version, encountered errors in program execution due to different versions;