配置 Ant 以使用 JUnit 4 [英] Configure Ant to use JUnit 4
问题描述
我用谷歌搜索了这个,但找不到任何帮助.
I googled for this, but I couldn't find any help.
我有一个简单的 JUnit 测试类.Eclipse 为我提供了两个选项来在 Run 配置窗口中的 Run as JUnit Test
中运行测试类,我看到 Test Runner JUnit 3
或 JUnit 4代码>.这工作正常.我的课程需要使用 JUnit4 runner.
I have a simple JUnit test class. Eclipse provides me with two options to run the test class in Run as JUnit Test
in the Run configuration window, I see Test Runner JUnit 3
or JUnit 4
. This is working fine. My classes need to use JUnit4 runner.
现在我正在尝试从 Ant JUnit 任务中运行它.但是,在我看来,Ant 默认使用的是 JUnit3.我不确定如何设置它以使用 JUnit4 测试运行器.我在类路径中只有 JUnit4 jar 文件,我将 ant-junit4.jar 从 ant lib 文件夹复制到我的类路径.这表明 [junit] 找不到主类:org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.程序将退出.
错误.
Now I am trying to run this from the Ant JUnit task. However, it seems to me that Ant is using JUnit3 by default. I am not sure how to set it up to use JUnit4 test runner. I have only JUnit4 jar file in the classpath and I copied ant-junit4.jar from ant lib folder to my classpath. That shows [junit] Could not find the main class: org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner. Program will exit.
error.
我也尝试过 JUnit4 Ant 任务.它显示没有 Junit4 ant 任务.帮助?
I also tried JUnit4 Ant task. It shows there is no Junit4 ant task. Help?
我只是将 ant-junit4.jar 留在了 ant/lib 文件夹中,并删除了 junit 任务中的 incudeantruntime
属性.它可以工作,但它再次使用 Junit3.
I just left the ant-junit4.jar in the ant/lib folder and just removed incudeantruntime
attribute in the junit task. It works, but again it uses Junit3.
编辑
我尝试从如下命令运行:
I tried running from command like following:
`java -classpath <myclasspath that has JUnit.jar as well> org.junit.runner.JUnitCore com.my.TestClass`
而且它工作正常.如何强制 ant Junit 任务使用此类 org.junit.runner.JUnitCore
?
and it works fine. How do I force ant Junit task to use this class org.junit.runner.JUnitCore
?
推荐答案
对于其他人的帮助,
Ant 默认使用 Junit3 测试运行器.我无法在 ant Junit 任务中指定测试运行程序.我使用了这篇帖子中的解决方法.
Ant is using Junit3 test runner by default. No way I can specify the test runner in ant Junit task. I used workaround like from this post.
谢谢@AlexanderMiles
Thanks @AlexanderMiles
这篇关于配置 Ant 以使用 JUnit 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!