Sts4: STS 4.4.0 no longer runs JUnit5 Tests - STS 4.3.2 did not have a problem

Created on 23 Sep 2019  路  27Comments  路  Source: spring-projects/sts4

When I took STS 4.4.0 last Friday and ran my JUnit5 tests, I received this error:

java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:75)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
    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.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

The tests were working fine with version 4.3.2. The only non-base install plug-in I have is "EclEmma Java Code Coverage 3.1.2", so I tried removing that from my install in 4.4.0 and that did not resolve the issue. When I downgraded back to 4.3.2, I was able to successfully run my tests again.

My basic STS install details for 4.3.2 are attached.
STSInstallDetails.txt

All 27 comments

Can you provide a sample project that could help us to reproduce the issue?

Sure thing. I'll put a quick project together this afternoon and attach it.

@mdehner-drivin Awesome, looking forward to it. Thanks in advance!!!

Here's what I did to create the attached ZIP:

  1. Installed STS 4.4.0
  2. Created a demo project using Spring Initializer. (Java 8, Maven)
  3. Added the demo project into the default 4.4.0 workspace.
  4. Imported the Maven project into STS Project Explorer like normal.
  5. Updated the pom.xml to exclude JUnit4 and include the JUnit5 libraries like I have them in our various projects. Additionally, added various standard dependencies (including Swagger) so it's more like one of the projects I've been working on.
  6. Renamed the application.properties file to application.yml and added minor configuration into it.
  7. Updated the Initializer generated DemoApplicationTests class to be JUnit5 instead of JUnit4.
  8. Ran DemoApplicationTests by right-clicking on the class, going to "Run As", selected "JUnit Test" and received the aforementioned stack trace.

I verified the "Test runner" is set to "JUnit 5" for the run configuration of DemoApplicationTests.

The attached is my entire workspace with the demo project included. Please let me know if any additional information is needed.
workspace-spring-tool-suite-4-4.4.0.RELEASE.zip

I debugged this a bit in e4.13 and e4.12 and I see the process being launched for tests having the same arguments including identical classpath entries. Seems like it is something with JDTs RemoteTestRunner or JUnit5TestLoader.
I can reproduce the issue with Eclipse 4.13 for Java Developers. Thus raised: https://bugs.eclipse.org/bugs/show_bug.cgi?id=551389

Overriding junit-jupiter.version property value 5.3.2(Spring Boot 2.1.8 default) to 5.5.2, it seems to be resolved.

Here is a workaround, when your project doesn't inherit from the spring-boot-parent and imports spring-boot-dependencies instead:

    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.5.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.1.8.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

@spydesk Thanks, Simon, for sharing the workaround here. Much appreciated!!!

Same problem here using gradle with spring boot 2.1.8 and Junit 5.5.2, unfortunately the solution is to migrate to IntelliJ =/

Alternatively, if you can, upgrading your project to Spring Boot 2.2.0 resolves the issue as well.

I'm experiencing a similar problem in STS 4.5.0 while it used to work in STS 4.4.2.

My project is using Spring Boot 2.2.2 and JUnit 5.5.2. Running the unit tests results in

Error: Could not find or load main class org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
Caused by: java.lang.ClassNotFoundException: org.eclipse.jdt.internal.junit.runner.RemoteTestRunner

No additional plugins installed and the project is imported in a new clean workspace. Running the same tests in STS 4.4.2 works as expected.

I can open a new issue if this is not the correct place to discuss this

@johanhammar I tried the following:

  • create a "New Spring Starter" project with web and actuator defendnecies.
  • Select the single test that comes with the project (it was called 'com.example.demo.DemoApplicationTests.contextLoads()').
  • Run as JUnit test

=> runs fine

This was with latest CI build of STS 4.5.1 build for Eclipse Platform 4.15 (latest milestone).

So either this problem has already been fixed somehow (could be it was a issue with Eclipse 4.14), or it is something specific to your project.

To determine this, I wonder if you could try the latest STS distrubtion snapshot to check if it works for you. You can download it from here: http://dist.springsource.com/snapshot/STS4/nightly-distributions.html

If the problem still happens on nightly for Eclipse 4.15 then please provide as much information as possible about your specific setup (most notably, since we suspect it is something specific to your project that may be triggering the bug, please attach a sample project to help reproduce the issue).

Hi @kdvolder Thanks alot

I created a Spring Starter with the mentioned dependencies. The tests run fine both STS 4.5.0 and STS Nightly (4.5.1.CI-B2135) on Windows.

Running tests in my project in STS 4.5.0 fails with an exception, as mention in my post above. However, in STS Nightly (4.5.1.CI-B2135) the tests works again.

So, it could be some combination of something in my project and Eclipse 4.14. I'll keep you updated if I find something. Is there anyway I can debug this?

Dunno if the recent fix to m2e (1.15.0 snapshots) are already part of the 4.5.1CI builds. See here for another fix to junit5 stuff. Can't figure if this is related: https://bugs.eclipse.org/bugs/show_bug.cgi?id=551298

Is there anyway I can debug this?

I'm not sure. If I had a project that triggers the bug I'd try poking at it in different ways until I figured something out, but it isn't exactly a well-defined process.

But since its working for you now in latest nightly build I don't think its worth spending a lot of effort on this. Whatever the problem was you ran into seems to be fixed and that's what really matters.

Hey I have created a simple maven project in sts 4.5.0 and added junit-jupiter 5.4.0 version with java 8 And facing similar issue :

java.lang.NoClassDefFoundError: org/junit/platform/commons/PreconditionViolationException
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:75)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.PreconditionViolationException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

Can anyone tell me what i am doing wrong or is this an issue with sts 4.5.0.

I am attaching my work space along with project
Spring Tools Suite 4.5.0.zip

@santo93hit Can you double check with the latest STS 4.5.1 CI build on Eclipse 4.15 from here: http://dist.springsource.com/snapshot/STS4/nightly-distributions.html

This looks very related to the bug that got fixed in Eclipse recently.

@martinlippert thanks it's working in STS 4.5.1 CI build on Eclipse 4.15

@martinlippert - I took Spring Tools release 4.5.1 today and have verified that the problem is no longer occurring. I'm not sure what the procedure is to close out an issue off your board(s). If I need to do the closing, could you let me know what I should do? Thanks very much.

I am not able to run JUnit4 IT tests in STS since 4.4.x due to the following error:

Error: Could not find or load main class org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
Caused by: java.lang.ClassNotFoundException: org.eclipse.jdt.internal.junit.runner.RemoteTestRunner

image

I had to go back to STS 4.3.1 to be able to run JUnit4 tests in STS. The project is using Spring Boot 2.1.12 with regular @SpringBootTest:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@ContextConfiguration(classes = RuntimeITConfiguration.class)
public class ProcessInstanceIT {
...
}

@igdianov I don't think that is the same problem as is being discussed in this ticket.

Also we haven't had reports from other users about problems running JUnit 4 (yet anyway). I don't mean to say this is not a real problem of course. I'm sure it is. However it is likely somewhat specific to your setup, your project and other details. So it would be great if you could:

a) raise a separate ticket for this and..
b) attach a small sample project and ...
c) describe precise steps to follow to reproduce the problem.

Then we can try to reproduce the problem and try to determine why this error happens.

Since the issue with running JUnit 5 tests have been resolved in Eclipse 4.15 and the latest CI builds have been approved to solve this, I am going to close this item here and mark it for milestone 4.6.0 (which will ship in March and will be the official release that is based on the then released Eclipse 4.1.5). Feel free to download nightly CI builds on Eclipse 4.15 from the mentioned download page, if you don't want to wait for the official release.

FYI: I'm having the same classnotfound issue as per @igdianov on STS 4.5.1 with JUnit 4 & Spring boot 2.2.4.RELEASE (sorry I realize this is close).

@woodforda Can you double check if that problem still exists in the latest nightly CI builds on Eclipse 4.15? You can get them from here: http://dist.springsource.com/snapshot/STS4/nightly-distributions.html. That would be awesome.

Sorry I have been on walkabout... Will do so

Unfortunately, I have issues with work infrastructure (virus protection) etc) blocking the update etc. so have been unable to test. apologies.

@woodforda No problem, thanks for letting us know. In the meantime, we releases Spring Tools 4 for Eclipse 4.6.0 on Eclipse 4.15, so maybe your work setup can be updated to that official release sometime soon to see if the problem persists or not. Let us know if there is anything that we can do to help.

Was this page helpful?
0 / 5 - 0 ratings