參考來源:http://squall.cs.ntou.edu.tw/cpp/91spring/CppUnitUsage.html

 

平常你寫完一個testcase

再測試程式地方就要加入

#include "ExampleTestCase.h"

CppUnit::TextTestRunner runner;
runner.addTest(ExampleTestCase::suite ());
runner.run();

如果覺得寫了N個TESTCASE 要寫N行include 跟 addTest 很煩的話 請參考以下方法 可以略過這2步驟

首先在ExampleTestCase.cpp 裡面加入

CPPUNIT_TEST_SUITE_REGISTRATION( ExampleTestCase);

然後執行測試裡面

runner.addTest改成

runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

這樣他就會自己去抓所有 繼承CPPUNIT_NS::TestFixture 的測試案例  

好用東西

arrow
arrow
    全站熱搜

    eric1300460 發表在 痞客邦 留言(1) 人氣()