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

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > cppUnit
linux下cppunit的安裝和使用
作者:網絡轉載 發布時間:[ 2014/1/3 9:42:06 ] 推薦標簽:cppunit 開源 源代碼

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

鏈接動態庫,編譯命令如下:
[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
然后執行:
[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() {}
    // 初始化函數
    void setUp ();
    // 清理函數
    void tearDown();
    // 測試加法的測試函數
    void testAdd ();
    // 測試減法的測試函數
    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>
//使用文本執行器
#include <cppunit/ui/text/TestRunner.h>
// 如果不更改TestSuite, 本文件后期不需要更改.
int main()
{
        CppUnit::TextUi::TestRunner runner;
      
        // 從注冊的TestSuite中獲取特定的TestSuite, 沒有參數獲取未命名的TestSuite.
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("alltest");
        // 添加這個TestSuite到TestRunner中
        runner.addTest( registry.makeTest() );
        // 運行測試
        runner.run();
}

上一頁12下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 国精品日韩欧美一区二区三区 | 天天干夜夜躁 | 亚洲国产成人影院播放 | 久久天天躁日日躁狠狠躁 | 成人福利网 | 日韩欧美一区在线观看 | 性夜黄a爽爽免费视频国产 性夜黄 a 爽免费看 | 一二三四视频社区在线1 | 国产高清美女一级a毛片久久w | 色视网 | 老子影院午夜伦不卡不四虎卡 | 中国一级黄色片 | 亚洲欧美日韩天堂 | 黄色免费在线网站 | 日韩精品一区二区三区中文精品 | 国产一区二区三区精品视频 | 日韩欧美在线中文字幕 | 国产欧美日韩一区二区三区 | 国产精品亚洲日日摸夜夜添 | 700av第一福利在线导航 | 亚洲国产观看 | 成人久久久久 | 无遮挡h肉动漫在线播放内衣 | 午夜国产福利在线 | 亚洲欧美网址 | 怡红院成人永久免费看 | 国产精品99爱免费视频 | 欧美人在线一区二区三区 | 伊人日韩 | 成人福利短视频 | 91日本| 全免费午夜一级毛片一级毛 | 成年美女黄网站色大免费观看软件 | 亚洲不卡视频在线观看 | 欧美日韩视频一区二区在线观看 | 日韩欧美一区二区三区免费看 | xxx日本免费 | 国产一级久久久久久毛片 | 无遮羞成人的动漫在线观看 | 日韩毛片高清在线看 | senima亚洲综合 |