Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test runner should recognize the Gradle test task which is needed to run the particular JUnit test #330

Open
piotr-rachwalik opened this issue Nov 18, 2024 · 1 comment
Labels
enhancement New feature or request Settings/Config If there are missing setting or configaration

Comments

@piotr-rachwalik
Copy link

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:

  1. The extension should automatically resolve what is the proper test task that can run the test
  2. Provide the option to manually set the Gradle command / configuration that could selectable in this view:
    Screenshot 2024-11-18 at 14 19 05
@sid-srini
Copy link
Member

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:

  1. Run tests with multi-selection:
    1. Filter the tests based on names, if needed.
    2. Multi-select test suites or items in the Testing panel.
    3. Click on the Run Test button next to any of the selected items.
  2. Modify the gradle configuration of the top-level test task to filter test tags/categories, names, packages etc.
    1. You may refer to Gradle's docs on test filtering and test grouping for this.
    2. 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.
    3. 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")
        }
    }
    1. This approach would work for Maven projects too for test filtering and test grouping, along with maven profiles.
  3. 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.
    1. This allows for complete customisation of the gradle command that you would like to launch.
    2. You may refer to VS Code docs to create a custom test task
    3. 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*"
            ]
        }    
    1. 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.

@sid-srini sid-srini added enhancement New feature or request Settings/Config If there are missing setting or configaration labels Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Settings/Config If there are missing setting or configaration
Projects
None yet
Development

No branches or pull requests

2 participants