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文件已經(jīng)安裝到/usr/local/lib中去了,但頭文件沒安裝到/usr/include中去
把cppunit-1.10.2的cppunit目錄復制到/usr/include下
4、導入lib
運行時要先設置環(huán)境變量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;
}