vscode-java-test icon indicating copy to clipboard operation
vscode-java-test copied to clipboard

Unable to run Junit 5 Tests using Java Test Runner

Open VijayKrishna32 opened this issue 11 months ago • 3 comments

Hello, We have our own vscode which is running inside a docker container & running on a browser. We are using

  • Java 17 -> which is from the vscode extension "Language Support for Java(TM) by Red Hat -> v1.35.1"
  • Debugger for Java extension -> v0.56.2
  • Test Runner for Java extension -> v0.40.1
  • Build Tool is Gradle for Java extension -> v3.13.2023120800

I have added the below dependencies in build.gradle file: testImplementation 'org.junit.jupiter:junit-jupiter:5.12.0' testImplementation 'org.junit.platform:junit-platform-launcher:1.12.0'

Running simple test: `package platform.demo.unittest;

import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals;

public class CalculatorTest { @Test public void testAddition() { int result = 2 + 3; assertEquals(5, result, "2 + 3 should equal 5"); } }`

Below is the settings I added to the User > settings.json: "java.test.config": { "name": "testconfig", "vmArgs": [ "-Dremoting.location=/home/myconnector/remoting.xml" ], }, "java.test.defaultConfig": "testconfig"

When I run the test by using Java Test Runner, I get the following error log: java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: Provider org.junit.vintage.engine.VintageTestEngine not found at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1219) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273) at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309) at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393) at java.base/java.lang.Iterable.forEach(Iterable.java:74) at org.junit.platform.launcher.core.LauncherFactory.collectTestEngines(LauncherFactory.java:158) LauncherFactory.java:158 at org.junit.platform.launcher.core.LauncherFactory.createDefaultLauncher(LauncherFactory.java:134) LauncherFactory.java:134 at org.junit.platform.launcher.core.LauncherFactory.lambda$create$2(LauncherFactory.java:128) LauncherFactory.java:128 at org.junit.platform.launcher.core.ClasspathAlignmentCheckingLauncherInterceptor.intercept(ClasspathAlignmentCheckingLauncherInterceptor.java:25) ClasspathAlignmentCheckingLauncherInterceptor.java:25 at org.junit.platform.launcher.core.DefaultLauncherSession.<init>(DefaultLauncherSession.java:57) DefaultLauncherSession.java:57 at org.junit.platform.launcher.core.SessionPerRequestLauncher.createSession(SessionPerRequestLauncher.java:75) SessionPerRequestLauncher.java:75 at org.junit.platform.launcher.core.SessionPerRequestLauncher.discover(SessionPerRequestLauncher.java:55) SessionPerRequestLauncher.java:55 at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.<init>(JUnit5TestReference.java:46)

  • With Junit5 dependency, it should use junit-jupiter-engine rt?
  • If I want to run the Junit 4 Tests with Junit5 then I need to use junit-vintage rt?
  • I am still not understanding on why it is complaining the junit-vintage-engine?

I was verifying any transitive dependency due to addition of dependencies in my gradle file -> Zero records found.

  • Can you help me what the error log says?
  • How to resolve it?
  • Is Java Test Runner using Junit-vintage-engine to run tests? If so, how can i exclude it?
  • Or something Else? Any leads will probably help me a lot

VijayKrishna32 avatar Mar 21 '25 17:03 VijayKrishna32

Your test is annotated with @test , not @Test - is that a typo?

raffian avatar Apr 02 '25 19:04 raffian

Do the tests work when running from the command line inside that docker container?

kropptrevor avatar Apr 03 '25 14:04 kropptrevor

Hi @VijayKrishna32, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

Here are a few suggestions to resolve the “VintageTestEngine not found” error and get JUnit 5 tests running:

• Remove the explicit junit-platform-launcher dependency – The Java Test Runner and Gradle’s JUnit 5 support bring their own launcher. Having only the launcher on your classpath without an engine can surface a stray service entry for VintageTestEngine. – In build.gradle, delete: groovy testImplementation 'org.junit.platform:junit-platform-launcher:1.12.0'

• Add the JUnit 5 engine and enable the platform in Gradle – Ensure you have both API and engine on your test classpath: groovy testImplementation 'org.junit.jupiter:junit-jupiter:5.12.0' // or, if you prefer to manage modules separately: // testImplementation 'org.junit.jupiter:junit-jupiter-api:5.12.0' // testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.12.0' – Tell Gradle to use JUnit Platform: groovy test { useJUnitPlatform() }

• If you still need to run JUnit 4 tests alongside JUnit 5 – Add the vintage engine: groovy testImplementation 'org.junit.vintage:junit-vintage-engine:5.12.0'

• Why Vintage?
The ServiceLoader mechanism merges all META-INF/services/org.junit.platform.engine.TestEngine files on the classpath. If an entry for org.junit.vintage.engine.VintageTestEngine exists but you didn’t include its jar, you’ll see exactly this “Provider … not found” error.

High-confidence references:

• Gradle’s JUnit 5 support (“useJUnitPlatform()”): https://docs.gradle.org/current/userguide/java_testing.html#sec:java_junit5

• JUnit 5 User Guide (adding the Vintage Engine): https://junit.org/junit5/docs/current/user-guide/#mqtt-vintage-engine

Other references with low confidence

• Issue #831 “Impossible to run Junit5 tests”
ClassNotFoundException for the Test Runner’s own launcher; not the same stacktrace.
https://github.com/microsoft/vscode-java-test/issues/831

• Issue #859 “Can’t run or debug JUnit 5 from secondary class”
Related to classpath layout in a lib folder, Windows-specific.
https://github.com/microsoft/vscode-java-test/issues/859

• Issue #1053 “Fails to load JUnit launch configuration in @ParameterizedTest”
Error on generic parameters in ParameterizedTest; unrelated engine complaint.
https://github.com/microsoft/vscode-java-test/issues/1053

• Issue #1643 “DynamicContainer and DynamicTest launching … does not work”
Problem invoking nested dynamic tests; different failure mode.
https://github.com/microsoft/vscode-java-test/issues/1643

The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

github-actions[bot] avatar Nov 13 '25 00:11 github-actions[bot]