Community
Participate
Working Groups
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).
The sample project uses JUnit 5.5.2, which ships as Java modules. Can you check whether JUnit 5.4.2 works, @Franz?
With 5.4.2 it doesn't work either.
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/
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.
Which version of Eclipse did you upgrade from? Do you see any error in the Console view or Error Log view?
I did not upgrade. I took a fresh zip-Archiv from the Download page. I only used my existing workspaces.
(In reply to Franz van Betteraey from comment #4) Looks like a Maven project configuration issue. Moving to m2e for comments.
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
Till, do you see this issue as well? Does it look similar to bug 526502?
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.
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.
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.
*** Bug 551389 has been marked as a duplicate of this bug. ***
Same here. JUnit5 tests where running fine in 2019-06, but stopped working after migration to 2019-09 last week.
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 ;).
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
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?
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.
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!
+1 to Daniel's comment ;)
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?
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
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?
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)
(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
New Gerrit change created: https://git.eclipse.org/r/155099
(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
*** Bug 530031 has been marked as a duplicate of this bug. ***
Gerrit change https://git.eclipse.org/r/155099 was merged to [master]. Commit: http://git.eclipse.org/c/m2e/m2e-core.git/commit/?id=7767192faacda387c578e1d6c74bcd1bec81f2c9
I'd set to resolved, but there is no target milestone for 1.15 yet.
Thanks Till.
@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.
(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.
I tested with the given update site and it solves the issue for me. Thanks!
I don't see anything at https://download.eclipse.org/technology/m2e/snapshots/1.15.0/latest/ If there another update site location?
(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.
> 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!
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
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.
Moved to https://github.com/eclipse-m2e/m2e-core/issues/