[英]Calculate the total sum of JUnit tests executed by Ant
我有一個Ant目標,該目標使用<batchset>
運行JUnit測試。
在運行時,將顯示以下內容:
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.497 sec
我想要的是所有類組合在一起執行的測試總數。 有沒有簡單的方法可以做到這一點?
<junit>
任務可以將測試結果輸出為XML文件。 這些XML文件可以使用免費的第三方XmlTask庫進行處理。
首先,在<junit>
,添加<formatter type="xml" usefile="true"/>
:
<junit>
<formatter type="xml" usefile="true"/>
<batchtest ... />
</junit>
然后,可以使用<xmltask>
組合XML文件並計算失敗和錯誤的總和:
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" />
<!-- Create a buffer named "testsuiteNode" that holds the -->
<!-- <testsuite> nodes from the JUnit reports. -->
<xmltask>
<fileset includes="*.xml"/>
<copy path="/testsuite" append="true" buffer="testsuiteNode"/>
</xmltask>
<!-- Create an XML document containing a single element: <root/>. -->
<!-- Then insert the <testsuite> nodes under <root/> -->
<!-- Then calculate the sums of the various errors and failures. -->
<!-- Finally, store the sums in various properties. -->
<xmltask>
<insert path="/"><![CDATA[<root/>]]></insert>
<insert path="/root" buffer="testsuiteNode"/>
<copy path="sum(/root/testsuite/@errors)" property="test-errors-count"/>
<copy path="sum(/root/testsuite/@failures)" property="test-failures-count"/>
<copy path="sum(/root/testsuite/@errors | /root/testsuite/@failures)"
property="test-failures-and-errors-count"/>
<copy path="sum(/root/testsuite/@tests)" property="test-total-count"/>
</xmltask>
<echo>test-errors-count: ${test-errors-count}</echo>
<echo>test-failures-count: ${test-failures-count}</echo>
<echo>test-failures-and-errors-count: ${test-failures-and-errors-count}</echo>
<echo>test-total-count: ${test-total-count}</echo>
樣本輸出
[echo] test-errors-count: 1
[echo] test-failures-count: 2
[echo] test-failures-and-errors-count: 3
[echo] test-total-count: 5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.