• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
demps_c
博客园    首页    新随笔    联系   管理    订阅  订阅
first cppunit program

编译

g++ -o hello hello.cpp -lcppunit

 

 

下面是代码

1 /*Program:testcppunit.cpp -- a simple hellow example which use the cppunit tool*/
2 #include <iostream>
3 #include <cppunit/TestRunner.h>
4 #include <cppunit/TestResult.h>
5 #include <cppunit/TestResultCollector.h>
6 #include <cppunit/extensions/HelperMacros.h>
7 #include <cppunit/BriefTestProgressListener.h>
8 #include <cppunit/extensions/TestFactoryRegistry.h>
9 class Test : public CPPUNIT_NS::TestCase
10 {
11 CPPUNIT_TEST_SUITE(Test);
12 CPPUNIT_TEST(testHelloWorld);
13 CPPUNIT_TEST_SUITE_END();
14 public:
15 void setUp(void) {}
16 void tearDown(void) {}
17 protected:
18 void testHelloWorld(void) { std::cout << "Hello, world!" << std::endl; }
19 };
20 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
21 int main( int argc, char **argv )
22 {
23 // Create the event manager and test controller
24 CPPUNIT_NS::TestResult controller;
25 // // Add a listener that colllects test result
26 CPPUNIT_NS::TestResultCollector result;
27 controller.addListener( &result );
28 // // Add a listener that print dots as test run.
29 CPPUNIT_NS::BriefTestProgressListener progress;
30 controller.addListener( &progress );
31 //
32 // // Add the top suite to the test runner
33 CPPUNIT_NS::TestRunner runner;
34 runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
35 runner.run( controller );
36 return result.wasSuccessful() ? 0 : 1;
37 }

posted on 2013-10-03 15:57  demps_c  阅读(185)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3