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.