【发布时间】:2015-01-07 01:04:00
【问题描述】:
我在谷歌上搜索过,但找不到任何帮助。
我有一个简单的 JUnit 测试类。 Eclipse 在运行配置窗口中为我提供了两个选项来运行Run as JUnit Test 中的测试类,我看到了Test Runner JUnit 3 或JUnit 4。这工作正常。我的课程需要使用 JUnit4 runner。
现在我正在尝试从 Ant JUnit 任务中运行它。但是,在我看来,Ant 默认使用 JUnit3。我不确定如何设置它以使用 JUnit4 测试运行器。我的类路径中只有 JUnit4 jar 文件,我将 ant-junit4.jar 从 ant lib 文件夹复制到了我的类路径中。这显示[junit] Could not find the main class: org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner. Program will exit. 错误。
我也尝试过 JUnit4 Ant 任务。它表明没有 Junit4 ant 任务。 帮忙?
编辑:
我只是将 ant-junit4.jar 留在了 ant/lib 文件夹中,并且刚刚删除了 junit 任务中的 incudeantruntime 属性。它可以工作,但它再次使用 Junit3。
编辑
我尝试从如下命令运行:
`java -classpath <myclasspath that has JUnit.jar as well> org.junit.runner.JUnitCore com.my.TestClass`
而且效果很好。如何强制 ant Junit 任务使用此类org.junit.runner.JUnitCore?
【问题讨论】: