The process of establishing a unit test using the CPPUnit.

zhaozj2021-02-16  78

Step 1: Establish a Console project that supports MFC, adds include and lib libraries to VC, copy cppunitd_dll.dll, testrunnerd.dll, testrunnerdsplugind to the project directory.

Step 2: 1. In the file containing the _tmain () function #include

#include

Write in _tmain ():

CPPUnit :: MFCUI :: Testrunner Runner;

CPPUnit :: TestFactoryRegistry? Istry = cppunit :: testfactoryregistry :: getRegistry ();

Registry.registerFactory (& CPPUnit :: TestFactoryRegistry :: getRegistry ("testcasename"));

Runner.addtest (registry.maketest ());

Runner.run ();

2. Establish a test class

In .h file #include

Class to inherit from Public CPPUnit: TestFixTure

Add a macro inside the class:

CPPUITE_TEST_SUITE (Classname);

CPPUNIT_TEST (FUNCTIONNAME);

...

CPPUNIT_TEST_SUITE_END ();

At least two functions should be added:

Void setup ();

Void Teardown ();

In the .cpp file, joining the macro:

CPPUNIT_TEST_SUITE_NAMED_REGISTRATION (ClassName, "TestcaseName");

3. Pay attention to some of the headers that need to be included.

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

New Post(0)