Repository navigation
VS Code does not recognize junit tests #1692
Description
Activity
I did some search and came across mention of a
.classpathfile. I do not see such file anywhere in my project.siddhsql What if you run
Java: Clean Java Language Server Workspace- i have done that many times. same result.…On Thu, May 16, 2024 at 6:59 PM Sheng Chen ***@***.***> wrote: @siddhsql <https://github.com/siddhsql> What if you run Java: Clean Java Language Server Workspace — Reply to this email directly, view it on GitHub <#1692 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A6NWEKY7MB2YKSRO2JZGRNTZCVQBVAVCNFSM6AAAAABH2WQIISVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJWGQ4TCNJTGE> . You are receiving this because you were mentioned.Message ID: ***@***.***>
Would you mind sharing the project to us?
- i am not able to do that. it is a big project with many modules.…On Thu, May 23, 2024 at 1:59 AM Sheng Chen ***@***.***> wrote: Would you mind sharing the project to us? — Reply to this email directly, view it on GitHub <#1692 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A6NWEK2UQEV3AEEWPHRV4L3ZDWVXHAVCNFSM6AAAAABH2WQIISVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRWGU4DSNJZGM> . You are receiving this because you were mentioned.Message ID: ***@***.***>
If there are
.settings,.classpath,.projectfiles located under your project folder.Please try to close your vscode, remove the above three files and open your vscode.
- I don't have any of these files. I have a settings.json under .vscode and it has following in it: ``` { "java.configuration.updateBuildConfiguration": "automatic", "java.compile.nullAnalysis.mode": "disabled", "java.test.config": { "vmArgs": ["--enable-preview", "--add-modules", "jdk.incubator.vector", "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED", "--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED", "--add-opens", "java.base/sun.security.util=ALL-UNNAMED", "--add-opens", "java.base/jdk.internal.ref=ALL-UNNAMED", "--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED", "--add-opens", "java.base/java.nio.channels.spi=ALL-UNNAMED", "--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED", "--add-opens", "java.base/sun.nio.cs=ALL-UNNAMED", "--add-opens", "java.base/java.nio.charset=ALL-UNNAMED", "--add-opens", "java.base/java.lang.ref=ALL-UNNAMED", "--add-opens", "java.base/java.nio=ALL-UNNAMED", "--add-opens", "java.base/java.nio.channels=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED", "--add-opens", "java.base/jdk.internal.loader=ALL-UNNAMED", "--add-opens", "java.base/java.util.regex=ALL-UNNAMED", "--add-opens", "java.base/java.security=ALL-UNNAMED", "--add-opens", "java.base/java.net=ALL-UNNAMED", "--add-opens", "java.base/sun.nio.fs=ALL-UNNAMED", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "--add-opens", "java.base/java.util.concurrent=ALL-UNNAMED", "--add-opens", "java.base/java.util.concurrent.atomic=ALL-UNNAMED", "--add-opens", "java.base/java.util.concurrent.locks=ALL-UNNAMED", "--add-opens", "java.base/java.util=ALL-UNNAMED" ] }, "git.ignoreLimitWarning": true } ``` I also tested on a Windows machine and there too VS Code does not recognize junit tests - no green button is displayed beside the tests.…On Thu, May 23, 2024 at 11:54 PM Sheng Chen ***@***.***> wrote: If there are .settings, .classpath, .project files located under your project folder. Please try to close your vscode, remove the above three files and open your vscode. — Reply to this email directly, view it on GitHub <#1692 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A6NWEKYAUVMEG72H2EX766TZD3P2HAVCNFSM6AAAAABH2WQIISVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRYG4YTENRUG4> . You are receiving this because you were mentioned.Message ID: ***@***.***>Reacted by Diego Cuenca and Scriptam
- it does not work for me though. i have tried cleaning the workspace many times.…On Wed, May 29, 2024 at 3:56 PM Diego Cuenca ***@***.***> wrote: Hi, I solved this problem in JAVA PROJECTS, Clean Workspace. Then the green buttons are displayed in tests. image.png (view on web) <https://github.com/microsoft/vscode-java-test/assets/41596984/038b7bad-f5c6-4349-b1cf-d3783e3ba431> — Reply to this email directly, view it on GitHub <#1692 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A6NWEKYFJLUPEF4GY4E2YG3ZEZMIZAVCNFSM6AAAAABH2WQIISVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZYGM4DKMZVGA> . You are receiving this because you were mentioned.Message ID: ***@***.***>Reacted by Diego Cuenca
siddhsql Is your problem resolved now?
There is an undergoing effort about support running test in gradle build server: microsoft/build-server-for-gradle#144
Once Once it's done, I'll check how to integrate that into the test runner extension.
Sheng Chen (@jdneo) 我遇到了同样的问题。
执行mvn test-compile -f 可以编译成功。但是在vscode里面找不到测试类。
更加有问题的是,ide似乎不识别test下面的java类,语法错误不会提示。清除目录、clear workspace都重复了很多次,都不解决问题。
能麻烦看下可能是什么问题导致?
aisong Could you share a sample project for your issue?
19 remaining items
我的Test图标也没有,我发现启动的时候有如下的报错。

[Error - 15:48:16] 2025年4月3日 15:48:15 FrameworkEvent ERROR org.osgi.framework.BundleException: Could not resolve module: com.microsoft.java.test.plugin [117] Unresolved requirement: Require-Bundle: org.jacoco.core; bundle-version="0.8.12" -> Bundle-SymbolicName: org.jacoco.core; bundle-version="0.8.12.202403310830" org.jacoco.core [116] Unresolved requirement: Import-Package: org.objectweb.asm; version="[9.7.0,9.8.0)"at org.eclipse.osgi.container.Module.start(Module.java:495) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel$2.run(ModuleContainer.java:2111) at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor$1$1.execute(EquinoxContainerAdaptor.java:146) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:2102) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:2042) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:2004) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1916) at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:341)我也是下载的最近的java的extension pack。
Please update the test runner extension (either the stable or pre-release)
Hi siddhsql, 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.
Based on the error
Preview features enabled at an invalid source release level 21, preview can be enabled only at source level 22VS Code fails to build your project and thus can’t discover tests. To resolve:-
Align your Maven compiler settings with your JDK version
<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <!-- set to your Java version --> <release>21</release> <!-- remove if you’re not using preview features --> <!-- <compilerArgs> <arg>--enable-preview</arg> </compilerArgs> --> </configuration> </plugin> </plugins> </build>
-
If you really need preview features:
• Use a matching JDK (e.g. JDK 22 for Java 22 previews)
• Or remove all--enable-previewflags and<enablePreviewFeatures>settings -
Verify VS Code settings don’t force an invalid source level (e.g. remove or correct
java.project.sourceCompatibilityor any preview flags) -
Run Maven: Update Project, then reload the window.
-
Ensure your test classes are
public, insrc/test/java, and annotated withorg.junit.jupiter.api.Test.
Other references with low confidence
Click to expand
-
impossible to launch test from vscode (JUnit5 tests not detected in VS Code)
impossible to launch test from vscode redhat-developer/vscode-java#2499 -
Java 16 doesn’t require --enable-preview… but VS Code still complains (preview-flag compilation errors)
Java 16 doesn't require --enable-preview for Records, Pattern Matching, but VS Code still complains redhat-developer/vscode-java#1854 -
Test UI does not load nor are tests found in Test Explorer (tests not discovered, downgrading extension works)
Test UI does not load nor are tests found in Test Explorer #1688
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!
Reacted by magick93 and Kat Rollo-
Do not listen to the AI. This is the solution that worked for me:
The compatible fix requires both sides to be updated:
redhat.java1.55.0or newer
Test Runner for Java0.46.0or newerredhat.java1.55.0 contains the JDT-LS/JDT fix, andTest Runner for Java0.46.0 contains the matching fixes for test discovery and bundled JUnit/ASM dependencies. I verified this combination with a plain Eclipse Java project usingjunit-platform-console-standalone-1.13.4.jar, and the JUnit 5 tests were discovered correctly.Minimal reproduction — I can reproduce this deterministically with a bare-bones Maven project, and the trigger is a single flag:
--enable-previewinmaven-compiler-plugin.Environment
- eclipse.jdt.ls
1.60.0(202606262232), java-test plugin0.43.1(loaded viainitOptions.bundles) - JDK 21.0.2 running the LS, matching the project's
<release>21</release> - Observed from Neovim (nvim-jdtls) calling the same LSP commands VS Code uses — confirming this is server-side and client-independent
Steps
- Create a project with this
pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>preview-repro</artifactId> <version>1.0.0</version> <properties> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.11.4</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>21</source> <target>21</target> <release>21</release> <compilerArgs> <arg>--enable-preview</arg> </compilerArgs> </configuration> </plugin> </plugins> </build> </project>
and
src/test/java/com/example/MiniTest.java:package com.example; import org.junit.jupiter.api.Test; public class MiniTest { @Test public void testOne() { System.out.println("one"); } @Test public void testTwo() { System.out.println("two"); } }
-
Open the project and wait for the Maven import to finish.
vscode.java.test.findTestTypesAndMethodsreturns[]— an empty result, not an error. No test lenses, nothing in the Test Explorer. -
Remove only the
<compilerArgs><arg>--enable-preview</arg></compilerArgs>block (change nothing else) and re-import. Tests are discovered immediately, with correct method-level items (testLevel = 6).
What still works with preview enabled (which is what makes this confusing to diagnose):
vscode.java.test.resolvePathcorrectly reports the test source folder/package (testLevel = 4)java.project.isTestFilereturnstrue- The test classpath resolves fine (junit-jupiter 5.11.4 present) and the test file shows 0 problems
- Hover on
@Testresolves the annotation and shows its Javadoc
Where it breaks (from inspecting
com.microsoft.java.test.plugin-0.43.1and theorg.eclipse.jdt.junit.corebundle shipped with jdt.ls):TestSearchUtils.findTestTypesAndMethods→JUnit5TestSearcher.isTestClass→JUnit5TestFinder.isTest(type)→ASTParser.setProject(...)+createBindings(...)yields no usable binding when the project options haveenablePreviewFeatures=enabled, soisTestreturnsfalsefor every type, the searcher gets filtered out, and the handler returns an empty list. This matches the error already quoted in this issue ("Preview features enabled at an invalid source release level 21, preview can be enabled only at source level 22") — ECJ only accepts preview at its latest supported source level, and on this code path the rejection silently degrades to "no tests found" instead of surfacing an error.vscode.java.test.findTestPackagesAndTypesreturns[]for the same reason, so the Test Explorer stays empty project-wide.Since
--enable-previewcombined with a fixed--releaseis a documented, supported Maven configuration, test discovery shouldn't silently return empty in this setup. A cleaner failure (e.g., surfacing the ECJ preview error) would already make this much easier to hit-diagnose. Thanks!
Update (2026-09-22): re-tested with the latest published components on both sides — the Maven path is still broken.
Following wenyt (@wenytang-ms)'s comment above, I re-ran the minimal repro with the newest available pieces:
- eclipse.jdt.ls 1.61.0 (
1.61.0.202609031315, the 2026-09-03 milestone — two months after the fix shipped in redhat.java 1.55.0) - Test Runner 0.46.0 (current marketplace build; note that both marketplace builds I checked bundle server plugin
com.microsoft.java.test.plugin0.43.1— the plugin jar itself does not appear to have been republished)
Result:
Scenario vscode.java.test.findTestTypesAndMethodssame project, --enable-previewremoved (control)✅ tests discovered on first attempt after import ( testLevel = 6items)with <compilerArgs><arg>--enable-preview</arg></compilerArgs>❌ returns [], retried 6× over ~90s afterinitialization job finishedSo the fix combination appears to cover the scenario it was verified with — a plain Eclipse-format project where preview is enabled via Eclipse project settings — but not Maven projects, where m2e maps
--enable-previewfrommaven-compiler-plugin<compilerArgs>into the JDT project options.To help narrow it down: with preview enabled,
vscode.java.test.resolvePathstill reports the test package correctly (testLevel = 4),java.project.isTestFilereturnstrue, the file reconciles with 0 problems, and hover on@Testresolves with full Javadoc — only theASTParser-binding-based test item resolution silently returns nothing.Reacted by issuelens- eclipse.jdt.ls
- added a commit that references this issue
on Sep 22, 2026 Thanks for the detailed minimal reproduction and the retest. I traced the server-side failure and opened #1938 with a fix for the test-discovery path.
With JDT's project options at
source=21, preview=enabled, the discovery AST reportsPreviewFeaturesNotAllowed(the JDT version tested accepts preview only for its latest source level). InfindTestTypesAndMethods,TypeDeclaration.resolveBinding()then returnsnull, and the extension returns[]before it reachesJUnit5TestFinder. The PR retries discovery using a parser-local preview-disabled option when the source level is older than JDT's latest, without changing project settings or the--enable-previewtest launch argument. It also covers project-wide discovery/nested tests and surfaces a diagnostic if bindings still cannot be resolved.I verified the behavior in an isolated VS Code extension host (JDK 21, JDT LS 1.61.0, Test Runner 0.46.0) with JDT preview explicitly enabled; the control without preview also works. One caveat: on my machine the Maven
compilerArgsin your POM alone did not turn on the JDT preview project option, so I have not independently reproduced that Maven-to-JDT import step. The new Tycho regression test also could not run locally because the target-platform build fails with missing JDT types. The PR is open for review; I am leaving this issue open until the fix is validated against your Maven setup and released.Reacted by issuelens






I am following the steps at this page to run Junit5 tests with VS Code and Maven. I have these extensions installed:
and my
pom.xmlhas:I have put my test classes in
src/test/java. but VS Code does not detect JUNIT5 tests. the green "lenses" or "buttons" do not show up next to the tests. In one of the logs I could see:and not sure if it is because of this.
related: #470