microsoft / microsoft/vscode-java-test

Unable to run Junit 5 Tests using Java Test Runner

Aperta
#1,757 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

ai-triaged gradle junit question test-discovery
Lingua principale
TypeScript
Stelle
340
Fork
173
Merge medio
1g 19h
PR unite (30g)
18

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il malfunzionamento con le dipendenze in build.gradle e le impostazioni java.test.config in settings.json, quindi esegui CalculatorTest tramite Java Test Runner. Leggi il ServiceConfigurationError segnalato e lo stack trace di JUnit5TestReference per tracciare quali motori di test vengono caricati. Il lavoro è completo quando hai identificato perché viene richiesto VintageTestEngine e hai documentato un percorso verificato di risoluzione o esclusione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, vscode
Ambito
devtools, testing-qa
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.