Getting started with CPPUnit Test Frame (1)
Author: cpluser Website: http://blog.enjoyImage.com email: enjoyImage@163.com blog: http://blog.9cbs.net/cpluser/ Demo Code Download
Test Drive Development (TDD) is the center of test as the development process, which insists, write the test code based on the product code before writing the actual code. The goal of the development process is to first pass the test, and then optimize the design structure. Test drive development is an important part of extreme programming. XUnit, a test framework based on test-driven development, which provides a convenient tool for us to use test driver development during the development process, so that we can quickly perform unit testing. Members of xUnit have a lot, such as JUnit, PythonUnit, etc. CPPUnit, which is introduced to you today is a member of the XUnit family, which is a test frame for C . This article does not introduce a detailed introduction to the CPPUnit source code, but only for CPPUnit's application. In this article, you will see: 1. Each component of the CPPUnit source code. 2, how to set your development environment to use CPPUnit. 3, how to add test code for your product code (actually in turn, add product code for test code. In TDD, there is a product code after test code) and test it through CPPUnit. The background of this document is: CPPUNIT1.9.0, Visual C 6.0, Windows2000. The statement is incorrect in the article, please criticize and correct. 1. The source code for the CPPUnit source code forms the CPPUnit test framework can be downloaded to http://sourceforge.net/projects/cppunit/. After downloading the decompression, you will see the following folder:
figure 1
The main folders are: DOC: CPPUnit instructions documentation. In addition, the root directory of the code, there are three documentation, named INSTALL, INSTALL-UNIX, INSTALL-WIN32.TXT. Examples: CPPPUnit provides an example of CPPUnit itself, which can learn how to develop using the CPPUnit test framework. Include: CPPUnit header file. SRC: CPPUnit source code directory. Second, after the first CPPUnit test environment decompressed the source code package, you must have anxious to see what CPPUnit is? OK, let's uncover the mystery of CPPUnit. 1. Enter the Example folder and open Examples.dsw with VC. Let's first take a look at the test example of the CPPUnit. These examples are for CPPUNIT itself unit test set, on the one hand, the CPPUnit author develops test cases written during the CPPUnit framework process, on the other hand, we can learn how to add test cases in our own project. 2. Set the CPPUNITTESTAPP project to Active Project (Win32 Debug), run after compiling, you can see the interface of the CPPUnit-based GUI mode for unit test Testrunner. Click "Run" and will see the interface as shown in Figure 2:
figure 2
This is a unit test result for CPPUnit, which shows that we have made 11 tests, all through. Click "Browse", we can also choose the unit test you want to do, as shown in Figure 3:
image 3
CPPUnit Tests all units in accordance with the structure of the tree. In CPPUnit, the minimum test unit is called a TestMethod test method, while multiple related test methods can form a TestCase test case. Multiple test cases also form a TestSuite test package. The test package is nesting together, forming the tree structure we have seen above. We can choose any of the tree nodes to perform unit testing. 3. Set the CPPUnitTestMain project to Active Project (Win32 Debug), compile and run, let's take a look at another environment for another unit test, as shown in Figure 4
This is a text-based unit test environment. CPPUnit provides several test environments, one based on text, one based on GUI, that is, Figure 3. 4. Set the HostApp project to Active Project (Win32 Debug), compile operation. Figure 5:
Figure 5
This is also a test conducted by CPPUnit itself, but it demonstrates it to we demonstrate a variety of failed tests. In the GUI-based test environment, if the test is unsuccessful, the progress bar shows red, and it is green. From test results We can see the failure unit test name, causing the reason why the test cannot pass, as well as the files and the number of files where the test failed statement is located. (Unbeated) CPPUnit Test Framework Getting Started (2)