Closed joshmanderson closed 5 years ago
@joshmanderson Would you mind to share the project to us?
@jdneo I can't do that, sorry – the project is private to my company. I know that this certainly complicates the issue replication process, but I'm afraid it's just not possible for me to share it.
@joshmanderson Ok I understand. I'll keep my eyes on this issue and update here if I find anything.
@joshmanderson One more question.
Can you see the test explorer at the sidebar (though no test items in it), or there is no test explorer at all.
I‘m wondering if the extension gets activated successfully.
I'm having the same issue on two entirely separate machines; code lenses have stopped appearing and no tests are showing up in the Test Explorer either.
@chrissantamaria Are you using Gradle as your building tools?
@jdneo Forgive me, I'm not all that experienced with Java packages, but I believe I am; I'm just using the standard Java Extension Pack. Projects were created with Eclipse beforehand.
@chrissantamaria Don't worry.
Would you mind to share the content of .classpath
file? Which is located at the base path of your project.
@jdneo
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
@jdneo Apologies for the late reply. The test explorer appears in the sidebar, but there are no tests shown within it.
I guess I got the root cause of this problem.
In our implementation, we will only search for the test items in the test
folders. Here is the implementation to determine the location of the test folder.
But the implementation could not solve all the problems.
A valid .classpath
file may look like this:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
...
</classpath>
For some unknown reason, some projects may not have test
attribute in its classpath entries. Just like @chrissantamaria provided. So I have to figure out a way to solve this scenario.
@jdneo
I can confirm that changing my .classpath
from this:
...
<classpathentry kind="src" path="src/test/java" />
...
to this:
<classpathentry kind="src" path="src/test/java" output="build/classes/test">
<attributes>
<attribute name="test" value="true" />
</attributes>
</classpathentry>
fixes the issue. Tests are now appearing in the test explorer (and can be run from there), and code lenses are appearing again (and working).
@joshmanderson Glad to know we have a workaround now. 😄
This workaround definitely worked for me too.
I had a project build in Eclipse that did not have "test" attributes in the classpathentry's. Adding this made the tests appear in the test explorer.
I have run into this error on one laptop but not another. Different code bases, so it may be project related, however I can successfully run the test goal using maven externally, so it's not a classpath problem. I have also confirmed that my .classpath test setup has the "test" attribute set to "true"
`<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>`
But when I run a test from the test explorer or from the test itself using the Run lens, an error dialog at pops up:
x Error
Source: Java Test Runner (Extension)
Hi @rdcoe,
Thanks for reporting.
If you can see the Code Lens but cannot run the test, then the problem you met seems to be different from this issue. Let's open a new issue and track it there: https://github.com/Microsoft/vscode-java-test/issues/561
Thanks.
Hi. Thanks for the tip @jdneo. I'm using gradle and I have another scenario, in that we separate out our tests into "test" and "integration" and thus the gradle_scope
for the integration tests is "integration". I'm not extremely experienced with gradle but I understand I shouldn't manually be editing the classpath file. Could the vscode extension be configured to look for something other than "test"? Can this be user defined? For example:
{
"tests_gradle_scope": "test,integration"
}
@badsyntax Good point! Let me consider how to expose such a kind of setting to the users. Thanks
Awesome thanks @jdneo I'm curious as to why test paths need to be specified in the first place, and why tests can't be discovered just via the Junit annotations? (If I were to guess, it would be for performance reasons)
Yes, it's just as you said, we don't want to search for the tests as long as the user opens a java file, this is a performance concern. But since it looks like a lot of projects needs to customize the test folders, the current implementation might be changed...
I'm still thinking if there is a better way to achieve that.
I'm encountering the problem that the code lenses aren't appearing for my tests and the test explorer isn't populated, even though the .classpath in my Maven-generated project does have the section
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
Is there any other workaround for the issue?
@jenny-ci Is the Language Support for Java
startup correctly?
I'm thinking to add a command like Mark as Test Folder
to update the .classpath
file. Will update when I have any progress.
Would gradle not overwrite this change to the .classpath file when rebuilding?
@badsyntax For some unknown reason, the .classpath
does not have test entry for some Gradle project. That's why we plan to add this command
Regarding "Mark as test Folder..." That might be fine. But at a minimum, some kind of warning when the Test Explorer is displayed, or maybe when refresh is run, that No "Test Folder" was found on classpath, or something.
My situation is that only the @Nested test does not show Run/Debug code lenses.Normal test,ParameterizedTest is OK.
my .classpath is below:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path=".apt_generated_tests">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Hi @coolboy0961,
We haven't supported that annotation yet. Tracked by #685
Here is the final solution for this issue:
The user can use <testSourceDirectory/>
to configure the test source paths.
The user can use sourceSets
to configure the test source paths.
All the source files are treated as testable files
It will be ignored.
This is for those files that do not belong to the current workspace, for example, you drop(open) a file into the VS Code from another place.
@jdneo - could you put this ^^ final solution info (or a link to your comment) into the README? It took me quite a bit of searching to find out that code lens was using my Gradle sourceSets, and more experimentation to find out that my additional test source sets needed to have their java and resources inside
test {}
in order for them to get the code lens "Run Test | Debug Test" shortcuts added.
Thanks!
@bcsrepo Sure, that's a good idea. I'll do it.
@jdneo I have tried setting <testSourceDirectory/>
in multiple different Maven projects and it doesn't seem to make a difference. It's always empty unless I manually edit the .classpath file.
Note that I am using the default src/test/java
paths in all of these projects.
@dampcake It would be helpful if you could share a sample project to repro the issue. This would be helpful for us to investigate what is going on?
https://github.com/dampcake/bencode (small single module Maven sample). https://github.com/dampcake/incubator-druid/tree/fix-eclipse (large multi-module Maven).
I have tried adding <testSourceDirectory/>
in the parent pom.xml as well as in each individual child pom.xml for multi module projects. After adding I have even tried cleaning the Java workspace and restarting. Nothing I do outside of modifying the .classpath
file directly seems to have any impact.
@dampcake I tried the first one and it works on my side.
Here are some places that you may take a look:
F1
> Java: Force Java Compilation
> Full
Still not able to enable it:
More info: Java Test Runner version: 0.18.1 VSCode version: 1.36.1 OS: macOS 10.14.5 Java version: 1.8.0_201 Maven version: 3.6.0
Other things tried:
git clean -fdX
and opening to regenerate everythingScreen shots:
Hmmm, tried on Mac as well.
So far I've no idea what is going on. Would you mind to share the .classpath
file that generated by the Java Language Server? You can find it at the root of your project.
Here is the generated .classpath
file:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
One thing I observed is that test scope is missing in the generated file. Here is mine:
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
...
Yes and if added manually like in https://github.com/microsoft/vscode-java-test/issues/470#issuecomment-444681714 it works, but it will not generate it with it in there. Was yours automatically generated like that?
Yes it's automatically generated. Wired....
@jdneo Thanks for working this through with everyone! I'm experiencing another weird issue, related to this--
My .classpath does not by default generate the
def testSources = entries.findAll {element -> element.path == "src/test/java" || element.path == "src/test/resources" || element.path == "src/integrationTest/java" || element.path == "src/integrationTest/resources" }
testSources.forEach { entry ->
entry.entryAttributes['test'] = 'true'
}
}
This adds the test attribute, but at the bottom, see here: Not Working ClassPath Gist
This does not work. However, if I let Eclipse do it , it generates the same xml, but with the test attribute at top, and it DOES work: Working ClassPath Gist
@dampcake is your problem get resolved?
If the test attribute is still not auto generated in your .classpath
, I suggest to file an issue in the Language Server repo: https://github.com/eclipse/eclipse.jdt.ls
Thank you @tthorntone for reporting this. I find a potential bug in the implementation. Let's discuss it in #759
@jdneo it's still not working on my macbook. I just tried opening a couple projects today in Ubuntu and it's working fine there. I will try to dig in later this week and see if I can figure out what's going on.
I am unable to see the tests in the Test Explorer. However, I can run the Maven test command as follows and that works.
mvn test -f "c:\Users\xxx\Documents\xxx\Java\xxx\pom.xml"
All the tests run to completion. Here is my configuration.
VS Code Version: 1.39.0 (user setup) VS Code Commit: 9df03c6d6ce97c6645c5846f6dfa2a6a7d276515
Electron: 4.2.10 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Windows_NT x64 10.0.18362
Java JDK 1.8.0.221 Language Support for Java v 0.50.0 Debugger for Java v 0.22.0 Java Test Runner v 0.20.0 Maven v 3.6.2
I tried the solution in Issue 470, and it did not solve the problem.
The Test Explorer is blank, and none of the CodeLens links appear in my unit tests.
@rmgalante Any output in your output channel? Or any thing you can see in the problems panel?
I've cloned the open source repo, gozer, at https://github.com/walmartlabs/gozer. You should be able to duplicate this problem with that open source repo.
The Problem panel is empty. "No problems have been detected in the workspace so far."
The output panels shows the following exception when I launch the project. It does not look relevant to the problem as it is just the FileWatcher exception.
Looking for git in: C:\Program Files\Git\cmd\git.exe Using git 2.21.0.windows.1 from C:\Program Files\Git\cmd\git.exe
git rev-parse --show-toplevel git rev-parse --git-dir git config --get commit.template Open repository: c:\Users\xxx\Documents\xxx\Java\VSCode\gozer git status -z -u git check-ignore -v -z --stdin git symbolic-ref --short HEAD git rev-parse master git rev-parse --symbolic-full-name master@{u} git rev-list --left-right master...refs/remotes/origin/master git for-each-ref --format %(refname) %(objectname) --sort -committerdate git remote --verbose Failed to watch ref 'c:\Users\xxx\Documents\xxx\Java\VSCode\gozer.git\refs\remotes\origin\master', is most likely packed. Error: ENOENT: no such file or directory, watch 'c:\Users\xxx\Documents\xxx\Java\VSCode\gozer.git\refs\remotes\origin\master' at FSWatcher.start (internal/fs/watchers.js:164:26) at Object.watch (fs.js:1232:11) at Object.t.watch (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\main.js:1:594401) at T.updateTransientWatchers (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\main.js:1:98291) at l.fire (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:50:539) at k.updateModelState (c:\Users\xxx\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\main.js:1:115979)
I can't use VS Code if I don't have a Task Runner. I hope this can be fixed.
I'm trying to figure out Debugging and Unit Testing for the first time. My class is using Eclipse, but I'd rather not download Eclipse if don't need to. I have the Run/Debug Code Lense for the main method, but I do not have the Run Test/Debug Test Code Lense appearing on my Unit Test.
I'm not entirely sure where to edit the classpath. I have a bunch of .java files in a folder, but there isn't any .classpath file. I have my Visual Studio extensions stored in a completely different place on my computer. I have a .java file I want to use for testing, but it's not specified as a test file as far as I know.
I search for .classpath files in the File Explorer, and I found like 5 (they all look identical, I think they are for different versions of Java) The one I have looks like:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
And I changed the 2nd classpathentry line to what it said above, but it didn't work and I don't really know what I'm doing
@adeick If your project for teaching purpose and is not complicated, you can use the standalone project in VS Code Java:
lib
See: https://code.visualstudio.com/docs/java/java-project/lib.mp4
Starting about a week ago, code lenses for each test, as well as the lens for the test class as a whole, have stopped appearing. Also, no tests appear in the test explorer panel, though this may have been a pre-existing issue – I've never used the test explorer before so I can't say for sure.
Restarting or reloading vscode does not fix the problem, nor does restarting the computer, nor disabling and re-enabling the test runner code lens – or the root vscode code lens – setting (also tried disable+restart and re-enable+restart).
Project is using gradle and tests use junit. Gradle version was upgraded from
2.14.1
to3.5.1
17 days ago, but the issue has only started occurring in the last week, so I'm not sure that the gradle upgrade is relevant to the problem.Has anyone else experienced similar issues recently and does anyone have any ideas as to what might be causing the issue?