microsoft / microsoft/vscode-java-test

Unable to run Junit 5 Tests using Java Test Runner

Open
#1,757 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-triaged gradle junit question test-discovery
Dominant language
TypeScript
Stars
340
Forks
173
Avg merge
1d 19h
Merged PRs (30d)
18

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the dependencies in build.gradle and the java.test.config settings in settings.json, then run CalculatorTest through Java Test Runner. Read the reported ServiceConfigurationError and the JUnit5TestReference stack trace to trace which test engines are being loaded. Done means identifying why VintageTestEngine is requested and documenting a verified resolution or exclusion path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, vscode
Domain
devtools, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.