You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Preview features enabled at an invalid source release level 21, preview can be enabled only at source level 22; code: 2098258
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.
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。
我看实际上jacoco的依赖和报错的对不上
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 22 VS 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-preview flags and <enablePreviewFeatures> settings
Verify VS Code settings don’t force an invalid source level (e.g. remove or correct java.project.sourceCompatibility or any preview flags)
Run Maven: Update Project, then reload the window.
Ensure your test classes are public, in src/test/java, and annotated with org.junit.jupiter.api.Test.
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!
The compatible fix requires both sides to be updated:
redhat.java1.55.0 or newer Test Runner for Java0.46.0 or newer
redhat.java 1.55.0 contains the JDT-LS/JDT fix, and Test Runner for Java 0.46.0 contains the matching fixes for test discovery and bundled JUnit/ASM dependencies. I verified this combination with a plain Eclipse Java project using junit-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-preview in maven-compiler-plugin.
Environment
eclipse.jdt.ls 1.60.0 (202606262232), java-test plugin 0.43.1 (loaded via initOptions.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
Open the project and wait for the Maven import to finish. vscode.java.test.findTestTypesAndMethods returns [] — 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.resolvePath correctly reports the test source folder/package (testLevel = 4)
java.project.isTestFile returns true
The test classpath resolves fine (junit-jupiter 5.11.4 present) and the test file shows 0 problems
Hover on @Test resolves the annotation and shows its Javadoc
Where it breaks (from inspecting com.microsoft.java.test.plugin-0.43.1 and the org.eclipse.jdt.junit.core bundle shipped with jdt.ls): TestSearchUtils.findTestTypesAndMethods → JUnit5TestSearcher.isTestClass → JUnit5TestFinder.isTest(type) → ASTParser.setProject(...) + createBindings(...) yields no usable binding when the project options have enablePreviewFeatures=enabled, so isTest returns false for 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.findTestPackagesAndTypes returns [] for the same reason, so the Test Explorer stays empty project-wide.
Since --enable-preview combined with a fixed --release is 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.findTestTypesAndMethods
same project, --enable-preview removed (control)
✅ tests discovered on first attempt after import (testLevel = 6 items)
with <compilerArgs><arg>--enable-preview</arg></compilerArgs>
❌ returns [], retried 6× over ~90s after initialization job finished
So 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-preview from maven-compiler-plugin<compilerArgs> into the JDT project options.
To help narrow it down: with preview enabled, vscode.java.test.resolvePath still reports the test package correctly (testLevel = 4), java.project.isTestFile returns true, the file reconciles with 0 problems, and hover on @Test resolves with full Javadoc — only the ASTParser-binding-based test item resolution silently returns nothing.
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 reports PreviewFeaturesNotAllowed (the JDT version tested accepts preview only for its latest source level). In findTestTypesAndMethods, TypeDeclaration.resolveBinding() then returns null, and the extension returns []before it reaches JUnit5TestFinder. 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-preview test 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 compilerArgs in 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.
Activity
siddhsql commentedon May 16, 2024
I did some search and came across mention of a
.classpathfile. I do not see such file anywhere in my project.jdneo commentedon May 17, 2024
siddhsql What if you run
Java: Clean Java Language Server Workspacesiddhsql commentedon May 17, 2024
jdneo commentedon May 23, 2024
Would you mind sharing the project to us?
siddhsql commentedon May 23, 2024
jdneo commentedon May 24, 2024
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.
siddhsql commentedon May 24, 2024
diegoxxc14 commentedon May 29, 2024
Hi, I solved this problem in JAVA PROJECTS, Clean Workspace. Then the green buttons are displayed in tests.

siddhsql commentedon May 30, 2024
jdneo commentedon May 30, 2024
siddhsql Is your problem resolved now?
jdneo commentedon May 30, 2024
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.
aisong commentedon May 30, 2024
Sheng Chen (@jdneo) 我遇到了同样的问题。
执行mvn test-compile -f 可以编译成功。但是在vscode里面找不到测试类。
更加有问题的是,ide似乎不识别test下面的java类,语法错误不会提示。
source action:

testing:

清除目录、clear workspace都重复了很多次,都不解决问题。
能麻烦看下可能是什么问题导致?
jdneo commentedon May 30, 2024
aisong Could you share a sample project for your issue?
19 remaining items
jdneo commentedon Apr 3, 2025
Please update the test runner extension (either the stable or pre-release)
iHowCool commentedon Apr 3, 2025
add for people who use trae(the ide developed by bytedance).you can download the lastest version of extension in vscode and install manually.
github-actions commentedon Nov 12, 2025
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
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>settingsVerify 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!
kathyrollo commentedon Jun 26, 2026
Do not listen to the AI. This is the solution that worked for me:
redhat-developer/vscode-java#4396 (comment)
wenytang-ms commentedon Jun 29, 2026
The compatible fix requires both sides to be updated:
redhat.java1.55.0or newerTest 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.desmondc9 commentedon Sep 22, 2026
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
1.60.0(202606262232), java-test plugin0.43.1(loaded viainitOptions.bundles)<release>21</release>Steps
pom.xml:and
src/test/java/com/example/MiniTest.java: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@Testresolves the annotation and shows its JavadocWhere 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:
1.61.0.202609031315, the 2026-09-03 milestone — two months after the fix shipped in redhat.java 1.55.0)com.microsoft.java.test.plugin0.43.1— the plugin jar itself does not appear to have been republished)Result:
vscode.java.test.findTestTypesAndMethods--enable-previewremoved (control)testLevel = 6items)<compilerArgs><arg>--enable-preview</arg></compilerArgs>[], 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.nvim-java-test-discovery: archive --enable-preview breaks java-test b…
wenytang-ms commentedon Sep 23, 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.