Cppunit User Guide

Source: Internet
Author: User

I already have a lot of instructions on cppunit on the Internet. I "repeat" it again to make it easier for me to recall it later and deepen my impression. How to Use cppunit as a beginner, instead of interpreting its internalCodeAnd some of your own experiences. Now, go to the topic.

First of all, let me briefly introduce the background: with the increase of development experience, we are more and more aware of the importance of the test code, and these highly targeted test codes are mainly ut ), it is important to manage these codes. Without the help of a testing framework, it would take a lot of effort to understand the failures and successes of these test cases. Cppunit completes this part of work for us. We only need to design test cases, and other cppunit can be easily implemented, such as displaying test results, if a problem occurs, you can easily locate the failure.

Well, how can we use cppunit. First, it is an open-source project. You can find the latest version online and download it. The following describes how to use cppunit.

1) copy the downloaded file to the installationProgramDirectory, such as D: \ Programs \.

2) use vs to open "\ SRC \ cppunitlibraries. DSW" (vc6.0 project) and find many compilation options. Note that if you need Unicode, You must select the Unicode option.

3.) After building cppunit, cppunit_dll, and testrunner, you can find the generated file in the \ Lib \ folder. Note that the generated lib or DLL

Files are divided into debug version and release version, which are applicable to the debug and release modes of your test project respectively.

4) include the above lib directory to the lib directory of.

5) create a dialog-based MFC Application and include the generated lib package in the project. The debugging and release versions must be clearly defined. The sample code is as follows:

# Ifndef _ debug

# Pargma commment (Lib ,"")

# Else

# Pargma comment (Lib ,"")

# Endif

6) Find the instance function of the main file in the test project, generate the dialog part of the code, and annotate it. Change the code to the testrunner interface.

7) then add the test class, which must inherit from ncpp_unit: testfixture. Then register it so that you can test it by looking for the registered test class in the main function.

8) then add the files generated by the test project (such as DLL, Lib, and other files) to the dependent file directory of the test project.

9) Write test cases in the test project, and then add the test cases to the test by using macros. In the test case, add the assertion macro provided by cppunit to indicate whether the test result is correct.

10) run the test and view the test results.

I am sorry for the fact that this article is not rich enough and detailed enough to understand it for myself. It may be necessary for a newbie to make it clear, if you have time, I will further enrich and add detailed processes. This article aims to help beginners who are new to cppunit get started quickly and make good tools available to more people. If you have any questions about cppunit usage, you can mail to: whp_lcyz@163.com and I will do my best to share what I know.

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.