Java Ant、JUnit和一个测试套件
因此,我正在使用JUnit设置自动回归测试,现在构建脚本被设置为调用TestSuite,它将一系列不同的测试打包到一个TestSuite中并返回它 构建文件:Java Ant、JUnit和一个测试套件,java,ant,junit,Java,Ant,Junit,因此,我正在使用JUnit设置自动回归测试,现在构建脚本被设置为调用TestSuite,它将一系列不同的测试打包到一个TestSuite中并返回它 构建文件: <target name="test-perform-check" depends="test-compile"> <junit printsummary="yes" fork="yes" haltonfailure="no"> <classpath path ="${
<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>
输出:
[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
我的问题是-为了让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
}
}
首先,我认为test属性必须与包含单个测试(而不是套件)的类一起使用。也许您可以使用一种模式让ant运行给定包中的每个测试,如下所示:
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
使用测试套件时,每次向套件中添加一个测试用例,您的语法应该如下所示:
suite.addTest(new VolumeCompare("testCase1"));
suite.addTest(new VolumeCompare("testCase2"));
suite.addTest(new VolumeCompare("testCase3"));
基本上,您没有传递要运行的测试的名称,因此它尝试运行“null”并失败。您可以发布您的
VolumeCompare.java
文件吗。如果我能修复它,我会把它扔到那里。是的,但我不想让ant马上运行所有的测试。在运行测试之前,我有一大堆事情要做(处理大量的数据),在这之前我不想返回测试套件。哦,对了,这就是你所说的“设置一大堆东西”,对不起。您始终可以选择设置一个ant任务来执行此数字压缩,然后使您的测试任务依赖于此数字压缩任务-当然,这将取决于测试类如何使用此数字压缩。。。您是否将数据传递给您的测试类?或者它存储在db/file中?好的,所以我发现其他文章的功能与您的基本相同()。所以,也许问题实际上在于你的测试本身——但很难用你发布的内容来判断。。。
suite.addTest(new VolumeCompare("testCase1"));
suite.addTest(new VolumeCompare("testCase2"));
suite.addTest(new VolumeCompare("testCase3"));