一。vs2005安装cppunit
1. 下载解压文件cppunit-1.12.1.tar.gz
2.编译
a.编译前先修改src\msvc6\testrunner\MsDevCallerListCtrl.cpp文件。
把import "libid:1A31287A-4D7D-413e-8E32-3B374931BD89" version("7.0") lcid("0") raw_interfaces_only named_guids中的7.0改为8.0
b.用vs2005打开工程cppunit-1.12.1/src/cppunit/CppUnitLibraries.dsw。由于是VC工程格式。会自动转化。yes to all就行。
c.打开“Build”菜单,选择“Batch Build...”,弹出“Batch Build...”对话框后点击“Select All”,然后Build。
3.vs2005中打开“Tools | Options...”,切换到Projects and Solutions->VC++ Directories标签页,选择‘include files',添加CPPUNITHOME/include/;切换到'libraries files'标签页,添加CPPUNITHOME/lib/;切换到'source files'标签页,添加CPPUNITHOME/src/cppunit/,保存。
4.测试工程配置
a.Project->properties->Linker->General标签页的Link Library Dependencies设为yes,Additional Library Diretories设为CPPUNITHOME/lib.
b.Project->properties->Linker->Input标签页的Additional Dependencies添加:Debug时为cppunitd.lib testrnunerd.lib Realease时为:cppunit.lib testrunner.lib
5.常见错误
d:\cppunit-1.12.0\cppunit-1.12.0\src\msvc6\dsplugin\stdafx.h
(12) : fatal error C1189: #error : This add-in is for VC++ 6.0
?only.
解决:不用处理
二.ubuntu安装cppunit
1、下载、解压
#include <iostream>
#include <cppunit/TestRunner.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
class Test : public CPPUNIT_NS::TestCase
{
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testHelloWorld);
CPPUNIT_TEST_SUITE_END();
public:
void setUp(void) {}
void tearDown(void) {}
protected:
void testHelloWorld(void) { std::cout << "Hello, world!" << std::endl; }
};
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
int main( int argc, char **argv )
{
// Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
// Add a listener that colllects test result
CPPUNIT_NS::TestResultCollector result;
controller.addListener( &result );
// Add a listener that print dots as test run.
CPPUNIT_NS::BriefTestProgressListener progress;
controller.addListener( &progress );
// Add the top suite to the test runner
CPPUNIT_NS::TestRunner runner;
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
runner.run( controller );
return result.wasSuccessful() ? 0 : 1;
}
编译,运行