How to use Cppunit for unit testing

Source: Internet
Author: User

First, the preface

Test-driven Development (TDD) is the center of testing as a development process, insisting that you write the code based on the product code before you write the actual code. The goal of the development process is to first enable the test to pass and then optimize the design structure. Test-driven development is an important part of extreme programming. XUnit, a testing framework based on test-driven development, provides a handy tool for us to use test-driven development in the development process, allowing us to perform unit tests quickly. There are many members of the xunit, such as Junit,pythonunit. The Cppunit, which is introduced today, is a member of the Xunit family, a test framework specifically for C + +.

This article does not do the detailed introduction to the Cppunit source code, but only to the Cppunit application makes some introduction. You will see:

Cppunit the various components of the source code;

How to set up your development environment to be able to use cppunit;

How to add test code to your product code (in turn, add the product code to the test code.) In TDD, there is the product code after the test code, and it is tested by cppunit;

This article describes the background: CppUnit1.12.0, Visual C + + 6.0, Windows XP. Please criticize the error in the article.

I. Installation of Cppunit

Source package from Http://sourceforge.net/projects/cppunit Cppunit. Cppunit is an open source product and the current highest version is 1.12.0. (select Development Snapshot on the page to which the above link points).

After downloading, unzip the source package to the local hard drive, for example, extract to E:\cppunit-1.12.0. The author removes the version number in the name of the folder, that is, the source package is uncompressed to E:\cppunit. After decompression, you will see the following folder:

The main folders are:

Doc:cppunit documentation for the description. In addition, the code root directory, there are three documentation, respectively, Install,install-unix,install-win32.txt;

Examples:cpppunit provides examples, but also to the cppunit itself test, through it can learn how to use the Cppunit test framework for development;

Include:cppunit header file;

Src:cppunit source code directory;

Config: configuration file;

Contrib:contribution, other people contribute to the perimeter code;

LIB: Store the compiled library;

SRC: source files, and compile the library of project, etc.;

The next step is to compile the work. In the src/directory, the CPPUNITLIBRARIES.DSW project file is opened with VC. Execute the Build/batch build, the generated library files will be copied to the Lib directory if the compilation is successful. Halfway through or some project compilation failed, generally without it, we focused on the debug and release versions of the two project Cppunit and Testrunner.

After compiling, a number of LIB, and DLL files are generated in the lib/directory, starting with Cppunit. CPPUNITD represents the debug version, and Cppunit represents the release version.

Cppunit provides us with two sets of frame libraries, one for static Lib and one for dynamic DLLs. Cppunit Project: Static Lib;cppunit_dll Project: Dynamic DLLs and Lib. In the development we can make the choice according to the actual situation.

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.