所以我正在使用JUnit设置自动回归测试,现在构建脚本被设置为调用TestSuite,它将一堆不同的测试打包到TestSuite中并返回它。
构建文件:
<target name="test-perform-check" depends="test-compile">
<junit printsummary="yes" fork="yes" haltonfailure="no">
<classpath path ="${mypath}" />
<jvmarg value="-Djava.ext.dirs=${extstar};${extpathextended};" />
<jvmarg value="-Dmipav=${mipav};" />
<sysproperty key="mipav" value="${mipav}"/>
<formatter type="xml"/>
<formatter type="plain" usefile="false"/>
<test name="test.JTest"/>
</junit>
</target>
JTest.java:
class JTest extends TestSuite {
public static Test suite () {
// set up a bunch of stuff
TestSuite suite = new TestSuite();
suite.addTest(new VolumeCompare());
suite.addTest(new VolumeCompare());
suite.addTest(new VolumeCompare());
suite.addTest(new FileExistence());
// do some other stuff
return suite;
}
}
输出:
[junit] Testcase: null took 0.002 sec
[junit] FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit]
[junit] Testcase: null took 0 sec
[junit] FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit]
[junit] Testcase: null took 0.002 sec
[junit] FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit]
[junit] Testcase: null took 0 sec
[junit] FAILED
[junit] null
[junit] junit.framework.AssertionFailedError
[junit]
[junit] Test test.JTest FAILED
我的问题是 - 我需要在buildcript中更改什么才能让ant正确运行测试?
编辑:
VolumeCompare.java:
public class VolumeCompare extends TestCase {
public VolumeCompare (...) {
// ctor
}
@Test
public void testVolume () {
// this print statement is never reached
System.out.println("testing volume");
// compare volumes here
}
}
答案 0 :(得分:0)
从junit task documentation开始,我认为test属性必须与包含单个Test(而不是Suite)的类一起使用。也许你可以使用一个模式让ant来运行给定包中的每个测试,如下所示:
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
答案 1 :(得分:0)
使用TestSuite时,您一次将测试用例添加到套件中,您的语法看起来应该更像这样:
suite.addTest(new VolumeCompare("testCase1"));
suite.addTest(new VolumeCompare("testCase2"));
suite.addTest(new VolumeCompare("testCase3"));
基本上你没有传递要运行的测试的名称,所以它试图运行“null”并失败。