2016-08-03 9 views
0

<batchset>でJUnitテストを実行するAntターゲットがあります。実行中に、以下が表示されAntによって実行されたJUnitテストの合計を計算します

Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.497 sec 

私が欲しいものを組み合わせて、すべてのクラスで実行されたテストの合計数です。 これを行う簡単な方法はありますか?

答えて

1

<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 
関連する問題