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

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

问题描述

我GOOGLE了这一点,但我找不到任何帮助。

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

我有一个简单的JUnit测试类。 Eclipse中为我提供了两个选项来运行运行作为JUnit测试的测试类在运行配置窗口,我看到测试运行的JUnit 3 JUnit 4中。这是工作的罚款。我的课需要使用JUnit4亚军。

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任务运行此。然而,在我看来,蚂蚁在默认情况下使用JUnit3。我不知道如何设置为使用JUnit4测试运行。我在classpath中唯一JUnit4 jar文件,我复制蚂蚁junit4.jar从蚂蚁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.

我也试过J​​Unit4 Ant任务。这表明没有Junit4 ant任务。
帮助?

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

编辑:

我刚离开蚂蚁junit4.jar在蚂蚁/ 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`

和它工作正常。如何强制蚂蚁junit任务使用这个类 org.junit.runner.JUnitCore

and it works fine. How do I force ant Junit task to use this class org.junit.runner.JUnitCore?

推荐答案

有关他人的帮助,

蚂蚁是用Junit3测试运行默认。没办法,我可以指定在蚂蚁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天全站免登陆