亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > cppUnit
linux下cppunit的安裝和使用
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2014/1/3 9:42:06 ] 推薦標(biāo)簽:cppunit 開源 源代碼

寫好上面的代碼后,接下來是編譯的過程,有兩種方式,一種是鏈接靜態(tài)庫,一種是鏈接動態(tài)庫,下面是鏈接靜態(tài)庫,編譯命令如下:
[root@testhost testexample]g++ -L /usr/local/lib/libcppunit.a hellolinux.cpp -lcppunit -ldl -o hellolinux
編譯選項中需要增加 -lcppunit -ldl兩個選項,-lcppunit是連接cppunit的庫,而cppunit的庫中使用了dl庫里面的函數(shù)。接下來你可以運行一下,看看結(jié)果如何了:
[root@testhost testexample]# ./hellolinux
Test::testHelloWorldHello, world!
: OK

鏈接動態(tài)庫,編譯命令如下:
[root@testhost testexample]# g++ hellolinux.cpp -lcppunit -ldl -o hellolinux


另一例子,把如下的代碼上傳到一個目錄,如math:
  
編譯命令如下:
[root@testhost math]# g++ -L /usr/local/lib/libcppunit.a Main.cpp MathTest.cpp -lcppunit -ldl -o MathTest
然后執(zhí)行:
[root@testhost math]# ./MathTest
..F


!!!FAILURES!!!
Test Results:
Run:  2   Failures: 1   Errors: 0


1) test: MathTest::testSub (F) line: 30 MathTest.cpp
assertion failed
- Expression: result == 1

整個的源代碼如下:
/////////////////////////////////////////////////////////////////////
// Function: A simple Math test
// DATE    : 2008-1-16
// Author  : xulinlin
// Vesion  : V1.0
// FileName: MathTest.h
/////////////////////////////////////////////////////////////////////

//因為需要使用TestFixture這個類,所以引入HelperMacros.h頭文件
#include "cppunit/extensions/HelperMacros.h"
//聲明一個測試類
class MathTest : public CppUnit::TestFixture {
    // 添加一個TestSuite
    CPPUNIT_TEST_SUITE( MathTest );
    // 添加測試用例到TestSuite, 定義新的測試用例需要在這兒聲明一下
    CPPUNIT_TEST( testAdd );
    CPPUNIT_TEST( testSub );
    // TestSuite添加完成
    CPPUNIT_TEST_SUITE_END();
protected:
    int x, y;      
public:
    MathTest() {}
    // 初始化函數(shù)
    void setUp ();
    // 清理函數(shù)
    void tearDown();
    // 測試加法的測試函數(shù)
    void testAdd ();
    // 測試減法的測試函數(shù)
    void testSub (); 
};

/////////////////////////////////////////////////////////////////////
// Function: A simple Math test
// DATE    : 2008-1-16
// Author  : xulinlin
// Vesion  : V1.0
// FileName: MathTest.cpp
/////////////////////////////////////////////////////////////////////
#include "MathTest.h"
// 把這個TestSuite注冊到名字為"alltest"的TestSuite中, 如果沒有定義會自動定義
// 也可以CPPUNIT_TEST_SUITE_REGISTRATION( MathTest );注冊到全局的一個未命名的TestSuite中.
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MathTest, "alltest" );
// 下面不變
void MathTest::setUp()
{
    x = 2;
    y = 3;
}
void MathTest::tearDown()
{
}
void MathTest::testAdd()
{
    int result = x + y;
    CPPUNIT_ASSERT( result == 5 );
}

void MathTest::testSub()
{
    int result = x + y;
    CPPUNIT_ASSERT( result == 1 );
}

/////////////////////////////////////////////////////////////////////
// Function: Main file for test
// DATE    : 2008-1-16
// Author  : xulinlin
// Vesion  : V1.0
// FileName: Main.cpp
// Compile : g++ -L /usr/local/lib/libcppunit.a Main.cpp MathTest.cpp -lcppunit -ldl -o MathTest
/////////////////////////////////////////////////////////////////////
#include <cppunit/extensions/TestFactoryRegistry.h>
//使用文本執(zhí)行器
#include <cppunit/ui/text/TestRunner.h>
// 如果不更改TestSuite, 本文件后期不需要更改.
int main()
{
        CppUnit::TextUi::TestRunner runner;
      
        // 從注冊的TestSuite中獲取特定的TestSuite, 沒有參數(shù)獲取未命名的TestSuite.
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("alltest");
        // 添加這個TestSuite到TestRunner中
        runner.addTest( registry.makeTest() );
        // 運行測試
        runner.run();
}

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 波多野结衣资源在线观看 | 成人综合激情 | h动态图男女啪啪27报gif | 亚洲欧美色图 | 亚洲一区日韩 | 99日韩精品 | 热热色网站 | www的视频| 一级免费毛片 | 欧美特黄一级大黄录像 | 91香蕉国产 | 一级片视频在线观看 | 曰本还a大片免费无播放器 曰本三级香港三级三级人 孕交videos小孕妇xx中文 | 日韩一道本 | 精品欧美一区二区在线看片 | 一个人看的免费视频www免费 | 黄视频在线观看网站 | 国产精品高清一区二区三区 | 日韩伦理视频 | 免费无遮挡无遮羞在线看 | 激情综合五月天 | 国产日产亚洲系列首页 | 波多野结衣免费观看视频 | 欧美日韩在线永久免费播放 | 黄色短视频网站 | a在线观看欧美在线观看 | 欧美成人香蕉网在线观看 | 在线视频h | 国产h视频在线 | 久爱视频在线 | 午夜亚洲视频 | 黄色大片在线观看 | 欧美伊人久久 | 国产婷婷综合丁香亚洲欧洲 | 一级特黄录像免费播放肥 | 日韩一级片在线播放 | 日韩欧美亚洲一区精选 | 国产亚洲欧美日韩在线观看不卡 | 国内精品1区1区3区4区 | 国产亚洲精品午夜高清影院 | 免费一级欧美片在线观免看 |