Ant、JUnit 和 TestSuite
因此,我使用 JUnit 设置自动回归测试,现在构建脚本被设置为调用 TestSuite,它将一堆不同的测试打包到 TestSuite 中并返回它。
buildfile:
<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
我的问题是 - 我需要在构建脚本中更改什么才能使 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
}
}
So I'm setting up automatic regression testing with JUnit, and right now the build script is set up to call a TestSuite, which packs a bunch of different tests into a TestSuite and returns it.
buildfile:
<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;
}
}
Output:
[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
My question is - what do I need to change in the buildscript to make ant run the tests properly?
Edit:
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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 junit 任务文档 中,我认为 test 属性必须与包含单个测试(而不是套件)的类。也许您可以使用一种模式来要求 ant 运行给定包中的每个测试,如下所示:
From the junit task documentation, I think the test attribute has to be used with a class that contains a single Test (rather than a Suite). Maybe you can use a pattern to ask ant to run every test in a given package, like this :
当使用 TestSuite 时,您一次向套件添加一个测试用例,您的语法应该看起来更像这样:
基本上您没有传递要运行的测试的名称,因此它尝试运行“null”并失败。
When using a TestSuite you add test cases to your suite one testcase at a time, your syntax should look more like this:
Basically you aren't passing the name of a test to run and so it tries to run "null" and fails.