We have migrated to both JUnit 4 and ant 1.7
The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant.
According to the Ant junit task documentation:
It also works with JUnit 4.0, including "pure" JUnit 4 tests using only annotations and no JUnit4TestAdapter.
But the documentation doesn't elaborate on how it should be configured.
Is there any special setting required for the junit task? Am I missing something? We have both Tests that extends TestCase (i.e. 3.8 style) and "pure" Junit 4 tests, could that be the problem?
I am using pure JUnit4 tests with Ant.
Here is the interesting part of my build file:
Make sure you have the latest version of the junit.jar file in the lib directory of Ant. As far as I know the required version is delivered with ant 1.7 or higher versions...
This happened to me and it was because I was both using annotations and extending TestCase.
When you extend TestCase you are assuming JUnit3 style so JUnit4 annotations are ignored.
The solution is to stop extending TestCase.
I also tried to do tests with JUnit 4.0 without JUnit4TestAdapter, i.e. without method
public static junit.framework.Test suite() { return new JUnit4TestAdapter(SomeTestClass.class); }
I use ant 1.9.4. Running ant test verbose (ant -v ) shows
Aha, but still there is some ant-junit-task. Downloading this shows in addition /usr/share/java/ant/ant-junit4.jar which is not added implicitly. I just added it explicitly:
and it worked. Without: no. I am aware that this solution is not beautiful at all...