Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 479730

Summary: Cannot run individual JUnit tests when importing Maven projects which uses JUnit < 4.6
Product: [Eclipse Project] JDT Reporter: Nicholas Wright <cs94njw>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED NOT_ECLIPSE QA Contact:
Severity: critical    
Priority: P3 CC: cs94njw, daniel_megert, jarthana, moritz.eysholdt
Version: 4.5   
Target Milestone: 4.6 M3   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Nicholas Wright CLA 2015-10-14 06:09:12 EDT
I recently upgraded to Eclipse Mars.
Now I cannot run individual JUnit tests.  This worked ok in previous versions of Eclipse.

I can run an entire file of JUnits.
But if I highlight a JUnit test method name, or select a specific JUnit test from the JUnit result viewer, then I see the following exception:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.junit4.runner.SubForestFilter.shouldRun(SubForestFilter.java:81)
	at org.junit.internal.runners.JUnit4ClassRunner.filter(JUnit4ClassRunner.java:110)
	at org.junit.runner.manipulation.Filter.apply(Filter.java:47)
	at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:34)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

People are mentioning this issue on Stack Overflow, but there doesn't seem to be any mention of a solution.

Please let me know if you need more information, or want me to try something.

-- Configuration Details --
Product: Eclipse 4.5.1.20150917-1200 (org.eclipse.epp.package.jee.product)
Installed Features:
 org.eclipse.jdt 3.11.1.v20150904-0015
Comment 1 Nicholas Wright CLA 2015-10-14 10:02:44 EDT
I've suggested this isn't an improvement, as this always worked in the past.
And the user is led down this path by the GUI too.
Comment 2 Nicholas Wright CLA 2015-10-16 09:37:19 EDT
Changed importance to critical.

I have a JUnit failure in my code.

I suspect the problem is that one JUnit is affecting subsequent JUnits.

But because I can't run them individually in Eclipse, I can't identify which JUnit is failing because of a bug, and which is failing because of previous state.
Comment 3 Markus Keller CLA 2015-10-16 10:00:11 EDT
Moritz, you added the SubForestFilter in bug 443498. Could you have look?
Comment 4 Markus Keller CLA 2015-10-16 10:36:42 EDT
Nicholas, the stacktraces for the org.junit.* methods don't match any recent version of JUnit. Could it be that your test project has been set up to run with org.junit 4.4 or 4.5? Maybe it's already enough to update your dependencies to require org.junit 4.12.
Comment 5 Nicholas Wright CLA 2015-10-16 11:43:16 EDT
You're right.  Upgrading to JUnit 4.9 made it start working in Eclipse.  Thanks!
Comment 6 Markus Keller CLA 2015-10-16 14:14:24 EDT
Glad to hear you can continue testing.

For the records: The problem is a breaking change in JUnit between 4.4 and 4.5. In 4.4, there was a method org.junit.runner.manipulation.Filter#apply(Runner), but in 4.5, the signature was changed to Filter#apply(Object).

It would be pretty hard to make this work with all versions of JUnit.

In 4.5, SubForestFilter fails because it uses an API that has only been added in 4.6:

java.lang.NoSuchMethodError: org.junit.runner.Description.getClassName()Ljava/lang/String;
	at org.eclipse.jdt.internal.junit4.runner.DescriptionMatcher$LeadingIdentifierMatcher.matches(DescriptionMatcher.java:95)
	at org.eclipse.jdt.internal.junit4.runner.DescriptionMatcher$CompositeMatcher.matches(DescriptionMatcher.java:38)
	at org.eclipse.jdt.internal.junit4.runner.SubForestFilter.collectIncludedDescriptions(SubForestFilter.java:49)
	at org.eclipse.jdt.internal.junit4.runner.SubForestFilter.apply(SubForestFilter.java:41)
	at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:670)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Starting from 4.6, everything is fine.