本文参照(纯属抄袭)了《cppunit helloworld详尽篇》一文,加以本人优美的词句进行了润色。特此声明。
操作系统系统:Ubuntu6,g++
软件版本:cppunit-1.10.2.tar.gz
(1)获得源码:
到cppunit.sourceforge.net上下载源代码。将其复制到到linux下或者是直接使用wget下载到linux下。
(2)解压缩:
使用以下命令即可解压缩
tar - zxvf cppunit - 1.10 . 2 .tar.gz
(3)编译安装
cd进cppunit-1.10.2目录下。
./configure
make
make install
make的编译的文件都在src/cppunit/.libs.
make install只是把链接库文件复制到/usr/local/lib,其他的似乎什么都没有做。
(4)复制头文件
make install没有把头文件安装到/usr/include中去,此时还需要手工去复制,
只要把include下面的cppunit目录复制到/usr/include下面就可以了,命令很简单,就不写了。
(5)配置链接库路径
这个时候,看起来似乎已经安装配置成功了,其实不然,在Ubutu、FC(已知的)动态链接库的配置文件里面并没有写入/usr/local/lib的路径,虽然可以编译过,但是你却发现会运行不了,会出现如是的错误:
./mytest: error while loading shared libraries: libcppunit-1.10.so.2: cannot open shared object file: No such file or directory
真是糟糕,此时你还需要配置一下链接库的路径,链接库配置文件为/etc/ld.so.conf,以下为修改办法:
vi /etc/ld.so.conf
在新起一行里面加入:
/usr/local/lib
然后再用ldconfig命令重新装载一下配置文件就可以了:
ldconfig
OK,此时你已经可以正常的编译并使用了^__^
(6)编写第一个HelloWorld
撰写mytest.cpp(从cppunit.sourceforge.net上copy下来的),代码如下:
#include
#include
#include
#include
#include
#include
#include
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
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 ;
}