我在Ant脚本中设置了以下目标来生成测试报告。它的工作做得很好,但我观察到的是,如果我编写了两个测试,我会获得单独的XML文件输出以及包含嵌套在标记内的相同信息的聚合XML文件。
有谁能告诉我如何避免生成此文件?
我的相关ANT目标和测试如下:
<target name="test" depends="init,compile">
<junit printsummary="yes" haltonfailure="no" showoutput="yes" >
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<classpath location="${instrumented.dir}" />
<classpath location="${classes.dir}" />
<!--
The instrumented classes reference classes used by the
Cobertura runtime, so Cobertura and its dependencies
must be on your classpath.
-->
<classpath refid="cobertura.classpath" />
<batchtest fork="yes" todir="${reports.xml.dir}">
<formatter type="xml" />
<fileset dir="${src.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${reports.xml.dir}">
<fileset dir="${reports.xml.dir}">
<include name="TEST-*.xml" />
</fileset>
</junitreport>
</target>
// TestCalc.java
import junit.framework.*;
public class TestCalc extends TestCase {
protected void setUp() {
// put common setup code in here
}
protected void tearDown() {
// put common cleanup code in here
}
public void testAddForTest2() {
int num1 = 3;
int num2 = 2;
int total = 5;
int sum = 0;
sum = Math.add(num1, num2);
assertEquals(sum, total);
}
public void testsubtractForTest2() {
int num1 = 5;
int num2 = 2;
int total = 3;
int sum = 0;
sum = Math.subtract(num1, num2);
assertEquals(sum, total);
}
public void testMulitplyForTest2() {
int num1 = 3;
int num2 = 7;
int total = 21;
int sum = 0;
sum = Math.multiply(num1, num2);
assertEquals("Problem with multiply", sum, total);
}
}
// TestMath.java
import junit.framework.*;
public class TestMath extends TestCase {
protected void setUp() {
// put common setup code in here
}
protected void tearDown() {
// put common cleanup code in here
}
public void testAdd() {
int num1 = 3;
int num2 = 2;
int total = 5;
int sum = 0;
sum = Math.add(num1, num2);
assertEquals(sum, total);
}
public void testsubtract() {
int num1 = 5;
int num2 = 2;
int total = 3;
int sum = 0;
sum = Math.subtract(num1, num2);
assertEquals(sum, total);
}
public void testMulitply() {
int num1 = 3;
int num2 = 7;
int total = 20;
int sum = 0;
sum = Math.multiply(num1, num2);
assertEquals("Problem with multiply", sum, total);
}
}
答案 0 :(得分:0)
以下是制作合并报告:
<junitreport todir="${reports.xml.dir}">
<fileset dir="${reports.xml.dir}">
<include name="TEST-*.xml" />
</fileset>
</junitreport>
来自JunitReport
:
合并JUnit任务生成的各个XML文件 最终将生成的合并文档应用于样式表 提供关于测试用例结果的可浏览报告。