您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
使用ant進行junit,并生成report
作者:網(wǎng)絡轉(zhuǎn)載 發(fā)布時間:[ 2014/1/13 11:03:17 ] 推薦標簽:junit ant 測試 單元

二、junitreport任務

可以采用junitreport任務生成html的報告。junitreport任務首先將生成的xml文件整合成一個xml文件,一般命名為TESTS-TestSuites.xml.然后再對xml文件進行轉(zhuǎn)換。其格式如下:

    <junitreport>

     <fileset dir="${test.data.dir}" includes="Test-*.xml"/>

     <report format="frames" todir=""/>

    </junitreport>

  在上面這個例子里,junitreport任務將整合test.data.dir下面的Test-*.xml文件,并且生成html文件框架.

  report表示生成有框架或無框架的javadoc。

三、如何只運行單個測試。

  對test和batchtest使用if/unless來實現(xiàn)選擇性的運行單個測試或者運行整個測試。

   <junit>

    <test name=${testcase} if="testcase"/>

    <batchset todir="${dest}" unless="testcase">

     <fileset .../>

    </batchset>

   </junit>

   if表示只要testcase這個property存在則會執(zhí)行test,unless表示將會執(zhí)行batchset,除非testcase這個property存在。因此如果想要運行單個測試,只需要在命令行中-Dtestcase=...即可。否則將會運行所有的testcases。

四、ant的其他一些數(shù)據(jù)類型及屬性

 1、JUNIT---sysproperty,系統(tǒng)屬性,定義和property類似。在java文件中可以通過System.getProperty()來獲得它的值。

   例如:

    <junit>

    ...

    <sysproperty key="docs.dir" value="./dest">

    </junit>

   在java文件中:

     System.getProperty("docs.dir");

   也可以使用properset定義一個屬性集,在junit中引用該屬性集,例如:

    <property name="property1" value="value1"/>

    <property name="property2" value="value2"/>

    <propertyset id="myproperty">

     <propertyref prefix="property1"/>

     <propertyref prefix="property2"/>

    </propertyset>

    <junit>

    ...

     <syspropertyset refid="myproperty">

    </junit>

  2、<reference refid="srcid" torefid="tarid"/>

    我的理解是定義一個引用的別名,在這里srcid是一個引用,為它定義了一個別名tarid,在當前project用srcid這個引用,如果該project中調(diào)用了另一個project的任務,則在另一個project使用tarid這個引用

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