Vscode-java-test: the Test Explorer is present outside java projects

Created on 4 Sep 2019  路  13Comments  路  Source: microsoft/vscode-java-test

VSCode Version: 1.37.1 (system setup)
Java Test Runner Version: 0.19.0
OS: Windows_NT x64 10.0.18362

Apologies if it's a known issue, i couldn't find any similar ones.

The behavior i was expecting was for the java text explorer to be shown only in java projects (or, equivalently, after opening a java file), but on my system whenever the extension is not completely disabled the sidebar panel is visible and accessible.

This is not consistent with the behavior of other testing extensions (e.g. microsoft/vscode-python).

Might I also suggest to change the name shown in the panel from "Test Explorer" to something more java specific?

testrunner

ux

Most helpful comment

Hi @erclu,

Thank you for your feedback. We have changed the explorer name in #796. For the issue that stopping test runner get activated. We will take a deep look and check if we have a solution there.

Thanks.

All 13 comments

Hi @erclu,

Thank you for your feedback. We have changed the explorer name in #796. For the issue that stopping test runner get activated. We will take a deep look and check if we have a solution there.

Thanks.

@jdneo are there any updates on this issue since you last commented.

@tristan957 Not yet, we are kind of watching if there are more votes. If more votes are coming we will prioritize it.

I would be interested in submitting a PR just because I find it so annoying.

Would you be able to provide guidance if I have questions?

@tristan957 How about hiding the icon by right-click the sidebar?

Screen Shot 2020-11-05 at 2 10 49 PM

Not a good solution for me because I some times work in Java environments and I don't want to have to manually remember that kind of thing

I see. So instead of just hiding the explorer. I think we can have a welcome view to help new users know how to start with using the extension (or something else about guidance, to make it more useful). Meanwhile, maybe a setting can also be added to determine whether to show it or not.

I'll update here once I have a more concrete idea.

Thanks

I mean I don't think it has to be a setting. The CMake Tools extension from Microsoft only activates and shows sidebar icon if there is a CMakelists.txt in your workspace. I just think this extension could do something similar like "if no java files, and no tests" don't show, or even just "if no java files".

I mean I don't think it has to be a setting. The CMake Tools extension from Microsoft only activates and shows sidebar icon if there is a CMakelists.txt in your workspace. I just think this extension could do something similar like "if no java files, and no tests" don't show, or even just "if no java files".

yeah I completely agree. I quickly searched through the vscode-python extension and it looks like they use this value in the when clause of the contributes.views.test[0].when key found in the package.json.

https://github.com/microsoft/vscode-python/blob/54dc5fe35c90b3b662def56858ff394a921a3907/package.json#L1928-L1936

the testsDiscovered clause seems to be defined and set to true in these files:

https://github.com/microsoft/vscode-python/search?q=%22testsDiscovered%27%2C+true%22

By glancing through the vscode extension documentation I believe they're using this feature specifically:

https://code.visualstudio.com/api/extension-guides/command#using-a-custom-when-clause-context

so a basic implementation of what they're doing would be imo to search for the presence of java files in the current workspace, maybe even of a "test" folder under src, which i believe is an accepted standard for the language, and if the search is successful add a custom when clause context:

vscode.commands.executeCommand('setContext', 'vscode-java-test:javaTestsDiscovered', true);

Then modify these lines

https://github.com/microsoft/vscode-java-test/blob/e2f930af338fb04ed710d90917e3cbfa2eeca9f0/package.json#L67-L74

to:

        "views": {
            "test": [
                {
                    "id": "testExplorer",
                    "name": "Java",
                    "when": "vscode-java-test:javaTestsDiscovered"
                }
            ]
        },

or something like that. Maybe the scoping "vscode-java-test" is unnecessary.

@erclu do you also have https://github.com/Microsoft/vscode-java-dependency and https://github.com/Microsoft/vscode-maven installed? They also show their views all the time. Thinking about making issues there as well along the same lines,

@erclu do you also have https://github.com/Microsoft/vscode-java-dependency and https://github.com/Microsoft/vscode-maven installed? They also show their views all the time. Thinking about making issues there as well along the same lines,

I have them but tbh I usually keep all my extensions globally disabled and enable them for the workspaces they're needed in so I'm not impacted by this issue as much anymore. But yeah go ahead!

I think it may also be worth to open an issue for vscode itself to suggest they increase the visibility of that section of the documentation, because it does look like a lot of extensions do not implement this feature adequately.

Yea all the extensions I have trouble with regarding this issue are actually all Microsoft-authored which is funny. I am opening all the issues against those extensions right now. Thanks for the effort you put into your previous comment. Easy to link to so that other extension maintainers can easily read how to use the feature.

New behavior: won't show the explorer if the extension is not activated, which will be available in the next release.

More details can be found in #1110

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Gueka picture Gueka  路  3Comments

gabloe picture gabloe  路  7Comments

ashoknailwal picture ashoknailwal  路  8Comments

NikolasKomonen picture NikolasKomonen  路  3Comments

ZhengguanLi picture ZhengguanLi  路  8Comments