I googled for this, but I couldn't find any help.
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.
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.
I also tried JUnit4 Ant task. It shows there is no Junit4 ant task. Help?
Edit:
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.
Edit
I tried running from command like following:
`java -classpath <myclasspath that has JUnit.jar as well> org.junit.runner.JUnitCore com.my.TestClass`
and it works fine. How do I force ant Junit task to use this class org.junit.runner.JUnitCore
?