我在我的 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);
}
}