Cppunit basic usage

Source: Internet
Author: User

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;

 

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.