运行“纯"使用 ant 的 JUnit 4 测试 [英] Running "pure" JUnit 4 tests using ant
问题描述
我们已经迁移到 JUnit 4 和 ant 1.7
We have migrated to both JUnit 4 and ant 1.7
测试在 Eclipse 中运行良好,但在使用 ant 运行测试时会忽略注释.
The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant.
根据 Ant junit 任务 文档:
According to the Ant junit task documentation:
它还适用于 JUnit 4.0,包括仅使用注释而不使用 JUnit4TestAdapter 的纯"JUnit 4 测试.
It also works with JUnit 4.0, including "pure" JUnit 4 tests using only annotations and no JUnit4TestAdapter.
但是文档没有详细说明它应该如何配置.
But the documentation doesn't elaborate on how it should be configured.
junit 任务是否需要特殊设置?我错过了什么吗?我们有扩展 TestCase(即 3.8 样式)的测试和纯"Junit 4 测试,这可能是问题吗?
Is there any special setting required for the junit task? Am I missing something? We have both Tests that extends TestCase (i.e. 3.8 style) and "pure" Junit 4 tests, could that be the problem?
推荐答案
我在 Ant 中使用纯 JUnit4 测试.
I am using pure JUnit4 tests with Ant.
这是我的构建文件中有趣的部分:
Here is the interesting part of my build file:
<junit printsummary="yes" haltonfailure="yes">
<formatter type="xml"/>
<classpath refid="path.test"/>
<batchtest fork="yes" todir="${dir.report.unittests.xml}">
<fileset dir="src">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
确保您在 Ant 的 lib 目录中拥有最新版本的 junit.jar 文件.据我所知所需的版本随ant 1.7或更高版本一起提供...
Make sure you have the latest version of the junit.jar file in the lib directory of Ant. As far as I know the required version is delivered with ant 1.7 or higher versions...
这篇关于运行“纯"使用 ant 的 JUnit 4 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!