Run Groovy tests in Visual Studio Code

Viewed 29

We have tests written in Groovy with the Spock framework, Junit as the runner, and Gradle as the build tool.

After installing all the relevant extensions (Test Runner for Java, Jave, and Gradle), I am still not able to run the tests using Visual Studio Code.

To run tests (in Intellij), we need to provide the following:

  • Java SDK (Java 11 in our case)
  • VM options (variables that are required for the tests)
  • Class Paths
  • Test name

My launch.json file looks like this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "java",
      "name": "Launch Current File",
      "request": "launch",
      "mainClass": "spock.TestSpec",
      "args": "",
      "vmArgs": [
        "-D example_arg1, -D example_arg2"
      ],
      "classPaths": [
        "example-tester.test"
      ]
    }
  ]
}

The project tree looks like this:

example-tester
        ├── README.md
        ├── build
        ├── buildSrc
        ├── gradle
        ├── src
        ├── .gradle
        ├── build.gradle
        ├── gradle.properties
        ├── gradlew
        ├── gradlew.bat
        ├── settings.gradle
        └── bin
            └── test
                └── spock
                    └── TestSpec.groovy

upon running, I am getting the following error:

Error: Could not find or load main class spock.TestSpec Caused by: java.lang.ClassNotFoundException: spock.TestSpec

Things I tried:

  • Cleaning Java Language Server Workspace
  • Added JavaSDK to the java.configuration.runtimes to settings.json

What are the things I must have/do to be able to run Groovy in vscode?

0 Answers
Related