MvG
MvG

Reputation: 60958

junit task in ant 1.9 with ivy fails with junit.framework.AssertionFailedError: No tests found

I've got a project based on ant and ivy, and I'm also using ivy to load dependencies. For some reasons, one of these projects has started to report a strange failure when using ant 1.9:

junit.framework.AssertionFailedError: No tests found in name.of.my.Clazz

This is strange because I've annotated test methods in my class uisng the JUnit4 @Test annotation, so there should be plenty of test cases to be found.

Upvotes: 0

Views: 509

Answers (1)

MvG
MvG

Reputation: 60958

Short answer: make sure you depend on ant-junit4 not only ant-junit.

I had to look at the sources to work this out. The core problem here is that the <junit> ant task will try to run the test case using JUnit3 semantics, and there are no test cases to be found according to that. The reason why it doesn't use JUnit4 mode is because the JUnit4 support of ant is a separate package for Maven or Ivy, namely org.apache.ant#ant-junit4 which depends on org.apache.ant#ant-junit but provides additional classes. In particular, without that package the JUnitTestRunner will fail to load CustomJUnit4TestAdapterCache and therefore fall back to JUnit3 style. At least since this commit.

There are some other questions around regarding this kind of error message, but they predate the commit I mentioned, so I guess they must have different causes. The answers seem to support this view. That's why I filed my own question and answer.

Upvotes: 5

Related Questions