CPPUnit Express (1)

xiaoxiao2021-03-06  106

Speed, swallow jujube, not especially, only explore the fur. Today spent two hours to study CPPUnit, which is generally learned about the framework of cppunit and simple use, and described below:

After studying the source code of CPPUnit, I want to draw its framework drawing, but to TOGETHER is indourtful. I have to make a good job. So how to use it. Looking back, there is time to explain its source architecture.

(1) Using CPPUnit within the Console program

1. Establish a class inherited from cppunit :: testfixture, the beginning of the class's statement uses CPPUnit's predefined macro cppunit_test_suite and cppUnit_test_suite_end to declare a TestSuite. The specific format is as follows (must contain cppUnit / extensions / helpermacros.h to use the macro mentioned below):

Class testofdummy: PUBLIC CPPUNIT :: TestFixTure {cppunit_test_suite (TestofDummy); ... // some test here, refer to point 2. CPPUnit_test_suite_end (); public: ... // your class definition};

2. Establish a member method in this class for test cases and add CPPUnit predefined macro cppunit_test to cppUnit_test_suite_end in class declaration to declare a test. The specific format is as follows:

in .h fileclass TestOfDummy: public CppUnit :: TestFixture {CPPUNIT_TEST_SUITE (TestOfDummy); CPPUNIT_TEST (testEqual); ... // other tests CPPUNIT_TEST_SUITE_END; public: void testEqual (); ... // other member functions}; in. CPP file # include

#include

Void TestofDummy :: TESTEQUAL () {cppunit_assert (1 == 1); ... // Other asserts}

3. Add a CPPUNIT predefined macro cppunit_test_suite_registration to register this testsuite (usually in the start section of the class). The specific format is as follows:

In.cpp file # include

#include

CPPUNIT_TEST_SUITE_REGISTRATION (TESTOFDUMMY); Void TestofDummy :: TESTEQUAL () {cppunit_assert (1 == 1); ... // Other asserts}

4. Get this registered TestSuite in the main method, and add this Suite into a Testrunner (in the Console program, usually use textui :: testrunner), then call the Testrunner's RUN method to run this Suite test. The specific format is as follows:

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

New Post(0)