Unit testing is an important component of extreme programming, CPPUnit and Junit, Duit are all a regression test framework written by Erich Gamma and Kent Beck, a good unit test tool for C languages, the following introduction to CPPUnit under VC6.0 Installation and use.
?? Part 1: CPPUnit installation.
1. Download CPPUnit: Download CPPUnit compressed files, 2. ? I use cppunit1.10.2
2. Compilation Project Document: Unzip CPPUnit1.10.2.tar.gz to the local hard drive, such as D: /CPPUnit1.10.2, open the project file in cppUnit1.10.2 with VC6.0 CPPUnitlibraries.dsw ,?
Select the current project to TestPlugInrunner, select the page under the BUILD menu, there will be a pair of words, select all Project, then press the Build button to generate the CPPUnit library file, where its location is in the CPPUnit1.10.2 / lib directory.
3. Set up the VC environment: Select the Tools-> Options menu, select the Directories Tab page, select include files in the Show Directories for drop-down box, add path cppUnit1.10.2 / include, such as my own D: / cppUnit1.10.2 / incrude Also increase the libary files path CPPUnit1.10.2 / lib, source files path cppunit1.10.2 / src / cppunit.
Click Browse in the dialog box that appears in the menu Tools-> Customize, and selects lib / TestrunnerDSPLUGIN.DLL.
At this time, pay special attention, turn off the VC6, set the path variable in the environment variable of Windows to add a path, cppunit / lib, such as D: /CPPUnit1.10.2/lib, otherwise, the dynamic connection library is not found in the later test project.
At this point, CPPUnit has been configured, and the code for writing tests, writing tests can be manually created, and the code is created below.
Void ChoStAppApp :: runUnittests ()
{
??? CPPUnit :: mfcui :: Testrunner Runner;
??? runner.addtest (cppunit :: testfactoryregistry :: getRegistry (). Maketest ();
??? runner.run ();
}
But you must manually create test projects, very inconvenient. The CPPUnit Visual Studio Application Wizard described below automatically creates a test framework, and we only need to write TestCase and Test methods.
Part II: CPPUNIT Visual Studio Application Wizard V0.1 Installation
1. ? Download CPPUnitAppWizard.zip: Files in the following address download
?
http://www.sourceXtreme.com/projects/cppunit/cppunitappwizard.zip?
2. • Installation Wizard: Unzip the download file to get an extension 3. ? For the Wizard file of AWX, 4. • Copy CPPUnitTester.awx to the Template directory of the VC. General location is Microsoft Visual Studio / Common / MSDEV98 / TEMPLATE.
At this time, you can restart VCs to have a CPPUnit TestApp Wizard Wizard under New Project. Select Enter the test engineering name to create a test engineering, and the default test fixture is Samplest, which is the same as we used in JUnit, you can create Testsuit, Testcase, write test method. For example, write a test method TestLogin, first declare the function in the SampleTest class header file, implement it in the original file. And use the macro cppUnit_test (testlogin) in the SampleTest class, add TestLogin. Build, Run, you can see the test interface. The first time in Browse is empty, click the Browse button, select Test fixTure, then select the test method. Click the RUN button to see the test results. (I started using the 1.8.0 version, and a browse is wrong, and then replaced with a 1.10.2 version, but there is a memory disclosure).
Thank SourceXtreme to create such a convenient tool for us.