配置Ant以使用JUnit 4 [英] Configure Ant to use JUnit 4

查看:179
本文介绍了配置Ant以使用JUnit 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经google了这个,但我找不到任何帮助。

I googled for this, but I couldn't find any help.

我有一个简单的JUnit测试类。 Eclipse在运行配置窗口中为我提供了两个选项来运行测试类:运行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蚂蚁任务。
帮助?

I also tried JUnit4 Ant task. It shows there is no Junit4 ant task. Help?

编辑:

我刚刚离开了蚂蚁-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.

修改

从命令如下:

 `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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆