cppunit测试工具

前段时间用过CPPunit,但都是直接拿来用的,今天自己装了下,测试通过,不过也花费了很多时间。。

1、下载cppunit,可以从sourceforge上找

2、解压 tar。。。

3、安装 ./configure   make   make install

4、配置:

将cppunit-version目录下include目录的cppunit目录cp到/usr/include下

5、配置链接库:

修改/etc/ld.so.conf文件,在最后加入一行: /usr/local/lib

修改后使用ldconfig,从新加载conf文件

然后利用ldconfig -v | grep cppunit 查看是否有libcppunit库,有的话说明加载正常

6、利用cppunit进行测试:

 

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;
 }
7、编译:可以用静态库和动态库来编译:
静态库:
g++ test.cpp -L/usr/local/lib/libcppunit.a -lcppunit -ldl -o test
动态库:
g++ test.cpp -lcppunit -ldl -o test
8、运行:
./test
可以看到输出,有一个ok就表示成功了
上午折腾了很久,刚开始没有加#include <cppunit/extensions/HelperMacros.h>这个头文件,结果一直找不到CPPUNIT_TEST_SUITE()和另外两个宏的定义。。。这三个宏是在该文件中定义的
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值