Bug 551298 - [JUnit 5] Missing 'Run As... - JUnit Test' or 'No tests found with test runner JUnit5'
Summary: [JUnit 5] Missing 'Run As... - JUnit Test' or 'No tests found with test runne...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 major with 7 votes (vote)
Target Milestone: ---   Edit
Assignee: Till Brychcy CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 530031 551389 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-09-20 04:09 EDT by Franz van Betteraey CLA
Modified: 2021-04-19 13:21 EDT (History)
26 users (show)

See Also:


Attachments
Sample project (68.29 KB, application/x-zip-compressed)
2019-09-20 04:09 EDT, Franz van Betteraey CLA
no flags Details
minimal-sample-project (3.33 KB, application/x-zip-compressed)
2019-12-25 02:25 EST, thomas menzel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Franz van Betteraey CLA 2019-09-20 04:09:59 EDT
Created attachment 279945 [details]
Sample project

Eclipse does not show the "Run As... -> JUnit Test" context menu entry anymore.
A sample projekt with one test and a screenshot is attached.

I used the packaged (zip) 2019-09 Eclipse Version for Java Enterprise Java Developers. The version info is '2019-09 R (4.13.0).

In some project the "Run As... -> JUnit Test" menu entry is visible but execution leads to a  'No tests found with test runner JUnit5' error message. A screenshot here ist also attached (inside the sample project).
Comment 1 Christian Stein CLA 2019-09-20 04:31:13 EDT
The sample project uses JUnit 5.5.2, which ships as Java modules.

Can you check whether JUnit 5.4.2 works, @Franz?
Comment 2 Franz van Betteraey CLA 2019-09-20 04:34:06 EDT
With 5.4.2 it doesn't work either.
Comment 3 Noopur Gupta CLA 2019-09-20 05:03:28 EDT
Can you reproduce it with a simple Java project (File > New > Java Project)? If so, please attach the same.

I don't see any issue in a simple Java project with or without module-info.java when the JUnit 5 container having JUnit 5.5.1 bundles is placed on the build path. I have tried with Eclipse 4.13 SDK build taken from https://download.eclipse.org/eclipse/downloads/drops4/R-4.13-201909161045/
Comment 4 Franz van Betteraey CLA 2019-09-20 05:07:58 EDT
I have only OpenJDK 11 defined as Java Runtime in eclipse but adding the explicit Java version for the compiler options seems to do the trick (after "Update Maven Project"). 

    <properties>
        <java.version>11</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <maven.compiler.release>${java.version}</maven.compiler.release>
    </properties>

Even Maven does not executes the tests without these options because the default source/target option seems to be 5.
So I guess the problem is in the sample project.

Nevertheless in my real project I inherit the Spring Boot parent POM 2.1.7.RELEASE with <java.version>11</java.version> and I guess the environment should fit here (JUnit 5.3.2). As described I see the "Run As..." but get the 'No tests found with test runner JUnit5' error.
My colleague found out that adding the junit-platform-commons library will resolve the error which I can confirm. 

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-commons</artifactId>
            <version>1.5.2</version>
            <scope>test</scope>
        </dependency>

But I am not sure if this is a reasonable workaround.
Comment 5 Noopur Gupta CLA 2019-09-20 05:15:39 EDT
Which version of Eclipse did you upgrade from?

Do you see any error in the Console view or Error Log view?
Comment 6 Franz van Betteraey CLA 2019-09-20 05:20:31 EDT
I did not upgrade. I took a fresh zip-Archiv from the Download page.
I only used my existing workspaces.
Comment 7 Noopur Gupta CLA 2019-09-20 05:23:25 EDT
(In reply to Franz van Betteraey from comment #4)
Looks like a Maven project configuration issue. Moving to m2e for comments.
Comment 8 Franz van Betteraey CLA 2019-09-20 05:25:04 EDT
As described adding the following dependency solves my problem

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-commons</artifactId>
    <version>1.5.2</version><!--$NO-MVN-MAN-VER$-->
    <scope>test</scope>
</dependency>

Btw, this is not necessary to run the tests in the console

Otherwise I get the following error in the console (as I noticed now)
java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createFilteredTest(JUnit5TestLoader.java:70)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:64)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.PreconditionViolationException
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 7 more
Comment 9 Noopur Gupta CLA 2019-09-20 05:26:20 EDT
Till, do you see this issue as well? Does it look similar to bug 526502?
Comment 10 D T CLA 2019-09-20 05:57:49 EDT
I have this "No tests found" bug as well.

With 2019-06 the projects worked fine. After the upgrade (via check for updates) it stopped working for me.


For me the "Run As... - JUnit Test" is still present on tests (except for test classes in the default package. I can execute them via the default package though).

Explicitly defining an up to date `junit-platform-commons` dependency fixes it for me.
As an alternative adding the "junit 5 library" to the project seems to fix the error as well.
Comment 11 Max Hohenegger CLA 2019-09-26 07:19:22 EDT
I can reproduce the NoClassDefFoundError-problem with 2019-09. Adding the JUnit 5 library works, but I have to add an additional hamcrest jar to the classpath because otherwise I see this problem: https://code.google.com/archive/p/hamcrest/issues/128
Adding the additional Maven dependency is not an option for me.
Comment 12 Schubert Fernandes CLA 2019-09-27 04:48:04 EDT
FWIW, Our JUnit tests were being run correctly using Eclipse 2019-06 and JUnit 5.4.2 but stopped running with the exception reported here after upgrading Eclipse to 2019-09.
Upgrading the project to JUnit 5.5.2 works around this issue and our JUnit tests now run correctly in Eclipse 2019-09.
Comment 13 Noopur Gupta CLA 2019-09-30 03:24:48 EDT
*** Bug 551389 has been marked as a duplicate of this bug. ***
Comment 14 Oosterlinck Alexandra CLA 2019-10-07 11:51:57 EDT
Same here.
JUnit5 tests where running fine in 2019-06, but stopped working after migration to 2019-09 last week.
Comment 15 Veit Guna CLA 2019-10-14 10:46:55 EDT
Same here. 2019-09, completely fresh install, imported "old" maven projects and tried to "Run as" as usual leads to the stacktrace pasted in the comments.
Open JDK 10.0.2 (zulu), we're using spring-boot-starter-parent 2.0.5 parent pom.

I can confirm, that a workaround by adding the Junit 5 lib to the eclipse projects works. Adding additional deps to the project I'm not very keen on "just for eclipse" TBH ;).
Comment 16 Ealse de Wilde CLA 2019-10-14 12:08:06 EDT
I've checked the release notes of Junit 5.5.0 and found a breaking change on class PreconditionViolationException. Checking the package name in the Eclipse exception and the package name of the class in my Spring Boot Maven project proved that there was a mismatch. 
So I added a property 
<junit-jupiter.version>5.5.2</junit-jupiter.version> 
to my pom.xml and the problem was solved
Comment 17 Mickael Istria CLA 2019-10-29 17:47:44 EDT
Do I get it right that in all cases, upgrading version of JUnit in Maven dependencies to 5.5.2 and then refreshing/updating the Maven project in Eclipse m2e (with right-click > Maven > Update Projects...) just fixes everything?
Ie, although there might be a glitch in m2e, this doesn't surface any longer when using latest JUnit release?
Comment 18 Franz van Betteraey CLA 2019-11-18 03:05:05 EST
Indeed, when using JUnit 5.5.2 this bug seems to be fixed.

Fortunately I was able to update my project to Spring Boot 2.2.1.RELEASE which updates JUnit to 5.5.2. This might not be possible in all cases but for me it is the solution to this problem now.
Comment 19 Daniel Raap CLA 2019-11-25 07:59:40 EST
Is this bug going to be fixed in Eclipse? So we can use any JUnit 5 version in our projects and like Maven Eclipse will run the tests!
Comment 20 Fernando Giannetti CLA 2019-12-04 14:43:48 EST
+1 to Daniel's comment ;)
Comment 21 Till Brychcy CLA 2019-12-21 10:14:38 EST
As written in comment 4, the problem with the attached sample project was just the wrong source level (because org.eclipse.jdt.internal.junit.launcher.TestKindRegistry.getContainerTestKindId(IJavaElement) checks 
 if (CoreTestSearchEngine.is18OrHigher(project)) {
    [...]
 }

As there still seems to be an issue, can somebody please upload a sample project that shows the problem?
Comment 22 thomas menzel CLA 2019-12-25 02:25:06 EST
Created attachment 281328 [details]
minimal-sample-project

this project has even less dependencies and it seems that for eclipse 2019-12 we need at least junit 5.5.0 so it works -- see the pom.xml
Comment 23 Till Brychcy CLA 2019-12-25 08:31:11 EST
Thanks, I can reproduce.

The problem is that the project contains no junit-platform-launcher, so the eclipse-supplied version  is used (in my case Eclipse4.14.app/Contents/Eclipse/plugins/org.junit.platform.launcher_1.5.1.v20190826-0900.jar).

The real problem is that junit-platform-launcher is not self-contained: This version needs the mentioned "org/junit/platform/commons/PreconditionViolationException", which is not included in the project-provided junit-platform-commons-1.4.2.jar. If you switch the project to Junit 5.5.0, it uses junit-platform-commons-1.5.0.jar, which has the required exception.

Workaround: add the matching junit-platform-launcher dependency:
   <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-launcher</artifactId>
      <version>1.4.2</version>
      <scope>test</scope>
    </dependency>

At that point I wondered how maven can find the matching junit-platform-launcher dependency and noted that 
it doesn't - no tests are executed with maven for this project.

I haven't found any documentation about the concept behind splitting junit 5 into all those jars. Is the assumption, that junit-platform-launcher must match the junit 5 version in the project? That would mean that Eclipse would have to bundle every existing junit 5 version, which cannot be the solution. Or should the eclipse-provided junit-platform-engine and junit-platform-commons version be forced on the classpath, if the eclipse-provided junit-platform-launcher is used?
Comment 24 Till Brychcy CLA 2019-12-25 11:29:38 EST
Just for the reference: Adding of Eclipse-provided junit-platform-launcher to the runtime classpath was implemented in bug 526502, and in bug 526502 comment 8 Igor suggested that real maven-compatible solution would be that m2e evaluates maven-surefire-plugin plugin runtime classpath, which would also solve bug 530031.

(Also for the reference: junit-platform-launcher was made incompatible with earlier versions of junit-platform-commons by https://github.com/junit-team/junit5/issues/1863)
Comment 25 Till Brychcy CLA 2019-12-27 12:19:22 EST
(In reply to Till Brychcy from comment #23)
> At that point I wondered how maven can find the matching
> junit-platform-launcher dependency and noted that 
> it doesn't - no tests are executed with maven for this project.
> 

Tests are executed in the example project with maven, if a new surefire version is used, e.g. by adding
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>3.0.0-M4</version>
			</plugin>
		</plugins>
to the pom.xml


(In reply to Till Brychcy from comment #24)
> [...] and in bug 526502 comment 8 Igor suggested that real maven-compatible solution would be that
> m2e evaluates maven-surefire-plugin plugin runtime classpath, which would
> also solve bug 530031.

Figuring out the junit-platform-launcher dependency version from maven-surefire-plugin is not trivial, as 
org.apache.maven.plugins:maven-surefire-plugin doesn't depend on org.junit.platform:junit-platform-launcher at all,
but org.apache.maven.surefire:surefire-junit-platform does.

And the way surefire finds this has changed between versions. Especially, surefire had some pretty complicated code for aligning the junit 5 dependencies added in https://issues.apache.org/jira/browse/SUREFIRE-1585, see https://github.com/apache/maven-surefire/blob/d013902c0de20f83c6a85aa4fffbc2b6bd99af88/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java#L3002
Comment 26 Eclipse Genie CLA 2019-12-29 14:33:07 EST
New Gerrit change created: https://git.eclipse.org/r/155099
Comment 27 Till Brychcy CLA 2020-01-01 06:38:34 EST
(In reply to Eclipse Genie from comment #26)
> New Gerrit change created: https://git.eclipse.org/r/155099
As written in comment 25, using surefire's dependencies isn't a clean solution either, so this patch simply adds the missing dependencies based 
on the versions of junit-platform-commons and junit-jupiter-api. 

Hard coding knowledge about the dependencies like this is a bit ugly, but the surefire developers haven't found a better solution either.

This can be disabled by setting the property m2e.disableAddMissingJUnit5ExecutionDependencies to true.

Pull request with tests: https://github.com/tesla/m2e-core-tests/pull/85
Comment 28 Till Brychcy CLA 2020-01-01 12:04:24 EST
*** Bug 530031 has been marked as a duplicate of this bug. ***
Comment 30 Till Brychcy CLA 2020-01-06 04:18:21 EST
I'd set to resolved, but there is no target milestone for 1.15 yet.
Comment 31 Mickael Istria CLA 2020-01-06 04:22:29 EST
Thanks Till.
Comment 32 Mickael Istria CLA 2020-01-06 05:09:19 EST
@Every interested party: please try upgrading to m2e snapshot including Till's patch using https://download.eclipse.org/technology/m2e/snapshots/1.15.0/latest/ p2 repository, and report here whether this patched build works for you or not.
Comment 33 Mickael Istria CLA 2020-01-07 09:54:29 EST
(In reply to Mickael Istria from comment #32)
> @Every interested party: please try upgrading to m2e snapshot including
> Till's patch using
> https://download.eclipse.org/technology/m2e/snapshots/1.15.0/latest/ p2
> repository, and report here whether this patched build works for you or not.

Up!
We can investigate a bugfix release of m2e with this one, but feedback from some of the reporters is necessary to justify the effort. If no feedback is given, we'll wait for March to release this fix.
Comment 34 D T CLA 2020-01-08 09:29:18 EST
I tested with the given update site and it solves the issue for me.
Thanks!
Comment 35 Martin Lippert CLA 2020-01-20 04:28:28 EST
I don't see anything at https://download.eclipse.org/technology/m2e/snapshots/1.15.0/latest/

If there another update site location?
Comment 36 Mickael Istria CLA 2020-01-21 03:24:05 EST
(In reply to Martin Lippert from comment #35)
> I don't see anything at
> https://download.eclipse.org/technology/m2e/snapshots/1.15.0/latest/

Looks like it was deleted for some unknown reason. I've retriggered a m2e build and content is back at this URL. Please try again.
Comment 37 Martin Lippert CLA 2020-01-24 07:15:07 EST
> Looks like it was deleted for some unknown reason. I've retriggered a m2e
> build and content is back at this URL. Please try again.

Awesome, thanks! Much appreciated!
Comment 38 Hans Müller CLA 2020-10-01 04:51:36 EDT
Now i updated to:

****************************************************************************

Eclipse IDE for Enterprise Java Developers (includes Incubating components)
Version: 2020-09 (4.17.0)
Build id: 20200910-1200
OS: Windows 10, v.10.0, x86_64 / win32
Java version: 14.0.1

****************************************************************************


...then i added "junit-jupiter-api-5.7.0.jar" AND "junit-vintage-engine-5.7.0.jar" to a "lib" folder in eclipse test project structure. Then i added them to the classpath in project settings.

After that, i created that test class:

```

package testing.junit;

import org.junit.jupiter.api.Test;

public class MyExampleJUnit5UnitTest {

	@Test
	public void abc()
	{
		
	}
	
	@Test
	public void cba()
	{
		
	}
}


```



...and there is still NO entry "Run as JUnit Test" (or similar) in run options.

When i use the latest 4.x version 4.13, that works without any problems.

How to solve that issue? Is there a workaround until it's fixed?


THank you for your feedbacks,
Jan
Comment 39 Hans Müller CLA 2020-10-01 04:53:58 EDT
I can't see any options to attach my project here as a zip. Because of that, i uploaded it here:

https://www.file-upload.net/download-14308050/JUnit5Test.zip.html


Hope that helps...

If not, so please don't hesitate to contact me. thx.
Comment 40 Denis Roy CLA 2021-04-19 13:21:49 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/