OS:linux
CppUnit:cppunit-1.11.6
1、下载、解压
到http://sourceforge.net/projects/cppunit下载,然后复制cppunit-1.11.6.tar.gz到/usr/src;
运行:tar -xf cppunit-1.10.2.tar.gz 解压缩;或者在WIN下直接解压
2、安装
进入cppunit-1.11.6目录下。依次运行下列命令
A :./configure;
B :make;
C:make check;
D:make install
3、copy *.h文件
.o, .a文件已经安装到/usr/local/lib中去了,但头文件没安装到/usr/include中去
把cppunit-1.10.2的cppunit目录复制到/usr/include下
4、导入lib
运行时要先设置环境变量LD_LIBRARY_PATH到cppunit的安装目录,也是/usr/local/lib,命令如下:
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
5、编写测试程序
testApp.cpp
#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;
}