计算 Ant 执行的 JUnit 测试的总和
Calculate the total sum of JUnit tests executed by Ant
我有一个使用 <batchset>
.
运行 JUnit 测试的 Ant 目标
当运行时,显示如下:
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
我有一个使用 <batchset>
.
当运行时,显示如下:
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