vscode-java-test
vscode-java-test copied to clipboard
Can run test from a .class file
Hi,
I have a tests.jar package that has the tests included, I did not write the tests, instead the've been downloaded by maven, the pom.xml has them as dependency. I've downloaded the sources as well, however Code Lens does not provide the Run Test| Debug Test above each test case, or the test class.
Here's the video, I have a TestSuite.java that is in the tests folder and it shows the Run Test | Debug Test, but when I navigate to the Broker.class test that is part of the tests.jar, the Code Lens does not show the individual Run Test | Debug Test above each test, like shown here. https://code.visualstudio.com/docs/java/java-testing#_rundebug-test-cases
video if it in action:
https://user-images.githubusercontent.com/60336163/117559253-8f135c80-b038-11eb-8a51-e1720ba4b9c1.mov
Running vsCode 1.56 w/ all extensions latest version.
The Run Test | Debug Test
code lenses will only show in the source code. The BrokerTest.class
is a compiled class file, so it will not show the code lenses.
Is there any special reason that needs to run the tests from a dependency jar?
It is the project that I am on, the instructor packaged his tests in a distributable jar that is a dependency of the project but sources are available for download which I have downloaded, before the download the fernflower decompiler tries to decompile .class, but after download the source code appears as if it was a .java file but vscode keeps the .class extension. IntelliJ does it differently, After downloading sources it copies the source code to a .java file in a temporary location so that debug tools and etc operate the same as if the .java is part of the project.
Thanks for the information. So if I understand correctly (please correct me if I'm wrong), IntelliJ will download the source for the test cases you mentioned before. And therefore, you are kind of dealing with the source code, and run the test from the source code, is that correct?
precisely. see screen shot below this is after sources downloaded. The green play buttons starts the test for each individual test case, but the .java test source code comes from compiled jar.
I know this is an edge case, tests are typically not distributed in .jar's instead tests are in the test folder part of the project you are working on, I was questioning if I was missing something more than anything.
Ok, so far the implementation is only register the code lens on *.java
files. So it is as expected.
I think the behavior of showing the content of the BrokerTest class in VS Code and IntelliJ are very similar. Only the file extension names are different from .java
and .class
.
So the question is whether we need to also apply it to *.class
files. Personally I'm ok with that, but I would like to wait a while and see if other users also have this request.
Got it, is this a setting that I can change in the interim, to include *.class files also?
Unfortunately, we haven't expose this setting for now. But this could be a potential way to support this request.