Misdirection in "Could not find matching test for pattern"?

I have a TestNG test that uses Spring configured via classic XML files. The bean ID is “foo”, and its class is “com.foo.Bar”. It turns out that the class com.foo.Bar is not on the classpath, which is my problem. But when I attempt to run the test via

$ gradle -DintTest.single=TheTest
clean intTest

I see this on my console:

FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':automated-testing-framework:intTest'.
> Failed to notify test listener.
   > Could not find matching test for pattern:
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

In fact, I discovered that the class is not on the classpath by turning up Log4J debug for Spring itself. But I could find no way to get Gradle to report this. I find that odd, because during the port of this build from Maven to Gradle, I did a lot of this type of bushwhacking work, and unless my code did something really bad, like calling System.exit(), I have always been able to get Gradle to tell me what really went wrong.

So my point is that even with -d, -s, and -i set (debug, stacktrace, info), I had to learn from Spring Log4J why the test could not acquire runtime resources. And that the “Could not find matching test for pattern” message was very misleading.

I can probe this further if the readership here is interested. iow, I can defer fixing my broken Spring config if you need more data on this problem.


I believe I figured this out.

I found that the test of interest was doing non-trivial Spring context config in the test class ctor. I moved that setup code to a TestNG lifecycle method annotated with @BeforeClass. That gives TestNG a fighting chance to sanely manage the setup failure and report the failure correctly. And it allows TestNG to upwardly communicate with Gradle so that the true root cause is reported vs both frameworks seeing code that just jumped the rails.