javavscode
javavscode copied to clipboard
Test runner should recognize the Gradle test task which is needed to run the particular JUnit test
Description
I have a multi subprojects Gradle Java project. I'm using custom Gradle test tasks to execute only particular test suites. Currently, I'm not able to run these tests using VS Code with Oracle Java platform extension, because the command always looks like this:
../../gradlew --configure-on-demand -x check cleanTest test --tests
I see two solutions:
- The extension should automatically resolve what is the proper test task that can run the test
- Provide the option to manually set the Gradle command / configuration that could selectable in this view:
Hi @piotr-rachwalik. Thanks for reaching out and outlining the issue you are facing.
Currently, the following options are possible for performing selective tests runs:
- Run tests with multi-selection:
- Filter the tests based on names, if needed.
- Multi-select test suites or items in the Testing panel.
- Click on the Run Test button next to any of the selected items.
- Modify the gradle configuration of the top-level
testtask to filter test tags/categories, names, packages etc.- You may refer to Gradle's docs on test filtering and test grouping for this.
- When Run Tests is invoked, you will notice in the Testing panel that only the included tests are run and the excluded tests/modules are skipped.
- An example of a gradle config which includes JUnit5 tests tagged "fast" and excludes those tagged "slow":
tasks.test { // Use JUnit Platform for unit tests. useJUnitPlatform() { includeTags("fast") excludeTags("slow") } }- This approach would work for Maven projects too for test filtering and test grouping, along with maven profiles.
- Add a VS Code task config to create one or more custom Test tasks which can be launched via the command Tasks: Run Test Task.
- This allows for complete customisation of the gradle command that you would like to launch.
- You may refer to VS Code docs to create a custom test task
- An example test task defined in tasks.json is:
{ "label": "test foo", "type": "process", "group": { "kind": "test", "isDefault": true }, "isTestCommand": true, "command": "${workspaceFolder}/gradlew", "args": [ "-x", "check", "test", "--tests", "*Foo*" ] }- Note: Since this mechanism is a completely independent task, it does not provide an integration with the Testing panel nor visually depict the Test Results.
Let us know if this helps in running tests for your project. Thanks.
In the future, we may enhance the extension to support configuring Test Run Profiles, although it appears that VS Code does not support creating a new test profile.