Cannot run tests when setting "java.import.maven.disableTestClasspathFlag": "true"
Hi, when setting the property "java.import.maven.disableTestClasspathFlag": "true" in .vscode/settings.xml the test extension seems to break.
No tests are discoverable in the Test Explorer and the run icons in the gutter disappear. Tested on multiple systems and on a fresh/clean install of VsCode. This is on Window, both natively and via WSL2.
"java.import.maven.disableTestClasspathFlag": "true" (Not working)
"java.import.maven.disableTestClasspathFlag": "false" (Works as expected)
The exxtension uses the test flag in the classpath to determine where the test source root is.
If that flag is disabled. It could not detect the test location. May I ask why would you like to turn it off?
I have a project that contains test-jars that need to be used in compile scope. Without setting that flag, any classes in these test-jars are not on the classpath and result in multiple class not found/ un-resolved compilation errors when attempting to run tests via the test-runner. These issues are not present when compiling/ running the tests through command line (maven in my case). I have created a simple project that demonstrates this: https://github.com/PunchedChimera/demo-test-jar-deps
Thank you for the attached project.
So far, the extension only detect the test root by searching the test classpath flag of the project. I'm afraid that AFAIK, there is no workaround right now.
To resolve the issue, maybe we can remove this restriction and directly search the test cases by those annotations. But I'm not sure the impact on the perf for this approach.
related with #464
Hi @PunchedChimera, 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.
The behavior you’re seeing is a known issue when java.import.maven.disableTestClasspathFlag is set to true:
• Root cause and tracking issue
Test Runner for Java relies on Maven’s “test” classpath flag to discover tests. When you disable it, tests aren’t picked up. See:
https://github.com/microsoft/vscode-java-test/issues/1782
The fix is to have the test runner search all source folders when that flag is true.
• Workaround
- In your workspace settings, enable metadata files at the project root:
"java.import.generatesMetadataFilesAtProjectRoot": true - Restart VS Code.
- Open the generated
.classpathat the project root and locate the<classpathentry>forsrc/main/java. Add thetestattribute:<classpathentry kind="src" output="target/classes" path="src/main/java"> <attributes> … <attribute name="test" value="true"/> </attributes> </classpathentry>
After this change the Test Explorer will rediscover your tests.
• Reference: https://github.com/redhat-developer/vscode-java/issues/2499#issuecomment-1159917457
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!