Linux 下 CppUnit的安装与使用
来源:互联网 发布:什么软件可以越狱 编辑:程序博客网 时间:2024/04/28 04:31
OS:ubuntu9.04
CppUnit:cppunit-1.12.1
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;
}
6、编译,运行
有两种方法
(a) 链接静态库。编译命令:
g++ -L/usr/local/lib/libcppunit.a testApp.cpp -lcppunit -ldl -o testApp
运行:
./ testApp
结果:
: OK
(b) 链接动态库。编译命令:
g++ testApp.cpp -lcppunit -ldl -o testApp
然后运行:
./ testApp
结果:
Test::
: OK
7、其他例子
在cppunit-docs-1.11.6中有文档money_example.html,该文档详细的介绍了测试、开发的过程;
转载:http://blog.csdn.net/lengxingfei/archive/2006/04/19/669659.aspx
- Linux 下 CppUnit的安装与使用
- cppunit在linux下的安装使用
- Linux下安装cppunit
- CppUnit的安装配置与使用
- CPPUNIT安装和使用(linux)
- 关于cppunit的安装及运行(linux下)
- cppunit 在vc6.0下的安装和使用
- Linux下如何使用CppUnit进行单元测试
- Linux下使用CppUnit组织单元测试
- Linux下的CppUnit 的HelloWorld手记
- Linux下的CppUnit 的HelloWorld手记
- Linux下Cppunit的简单运用
- Linux下Cppunit的简单运用
- 在 VS2005 下使用 CppUnit 的准备工作
- CppUnit 安装和使用
- CppUnit安装及使用
- Linux下MPICH的安装与使用
- Linux下libpcap的安装与使用
- SQL SELECT TOP N equivalent in ORACLE and MySQL
- SuperMap WebGIS应用案例(.NET篇)
- 水晶报表打印IE预览时只出来一半的原因
- ARM-thumb 过程调用标准!
- MOV指令
- Linux 下 CppUnit的安装与使用
- C/S,B/S,分层架构之间的灵活搭配优势
- javascript创建类五法
- JDK 在 Linux 安装 - .bin
- 如何提升IT人员职业价值
- JDK 在 Linux 安装 - .rpm.bin
- JDK的安装和环境变量的配置
- oracle 里sysdate里操作
- 程序设计原则之我见