microsoft / vscode-java-test

Run and debug Java test cases in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test
Other
290 stars 124 forks source link

Cannot run tests when setting "java.import.maven.disableTestClasspathFlag": "true" #1690

Open PunchedChimera opened 2 months ago

PunchedChimera commented 2 months ago

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)

image

"java.import.maven.disableTestClasspathFlag": "false" (Works as expected)

image

jdneo commented 2 months ago

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?

PunchedChimera commented 2 months ago

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

jdneo commented 2 months ago

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.

jdneo commented 1 month ago

related with #464