您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 >
Delphi單元測試工具Dunit介紹
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/3/7 13:32:36 ] 推薦標(biāo)簽:

 Dunit基本介紹

    Dunit是Xunit家族中的一員,用于Dephi的單元測試。是Extreme Programming測試實現(xiàn)Xtreme Testing的一種工具。Dunit是一個Free的測試工具,沒有代碼覆蓋率功能。

    Dunit的官方Web Site 是https://sourceforge.net/projects/dunit/。

    使用Dunit應(yīng)該先看看Dunit安裝目錄下的docREADME.html。本文也是參看Readme寫的。

    配置測試環(huán)境
    在使用Dunit前應(yīng)該將下載的Dunit解壓。然后后將Dunit的路徑加到菜單 Tools->Environment Options 里面的Library->Library Path中。

  Dunit的主要文件

TestFramework.pas  The framework itself.
TestExtensions.pas   Decorator classes that may be used to extend test cases.
GUITesting.pas    Classes for testing user interfaces (Forms and Dialogs).
TextTestRunner.pas  Routines to run tests in console mode.
GUITestRunner.pas  The graphical user interface to the framework.
GUITestRunner.dfm  The GUITestRunner Form

 

    Dunit基本實現(xiàn)方法(GUI方式)
    Dunit的基本實現(xiàn)思路是將被測試代碼(單元)與測試代碼(單元)分開。提供一個FrameWork及一個運行界面。 所有的測試單元都應(yīng)繼承TtestCase。

    運行GUI界面

    運行TestCase

    這里要注意的一點是SetUp方法和TearDown是每個測試方法運行時都被調(diào)用的,如果想要只運行一次Setup及TearDown,應(yīng)該使用TtestSetup類,具體情況后面《Dunit附加功能》一節(jié)。

    創(chuàng)建一個簡單的例子
    創(chuàng)建一個被測試的Project
    創(chuàng)建一個名為BeTestProject的Project,將確省的Unit1保存為BeTestUnit.pas文件。把確省的TForm1改名為BeTestForm中增加一個Public的函數(shù)BeTestFunction,BeTestFunction代碼如下:

    function BeTestForm.BeTestFunction(i,j:integer):integer;

    begin

    Result:=i*j;

    end;

    創(chuàng)建一個測試Project
    創(chuàng)建新的Project
    再創(chuàng)建一個Project,命名為TestProject。如果沒有和BeTestProject放在同一目錄,將BeTestProject的存放路徑加到加到菜單 Tools->Environment Options 里面的Library->Library Path中。

    編寫TestCase
    刪除確省的Unit1(Form1),創(chuàng)建一個的Unit,注意不是Form.

    將創(chuàng)建的Unit保存為TestUnit,在interface中加入以下代碼

    uses

    TestFrameWork,BeTestUnit;

    TestFrameWork是每個TestCase都必須使用的,后面要使用的TtestCase等類的定義都在TestFrameWork中。BeTestUnit是將要被測試單元。

上一頁1234下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd