How to run Spock tests with Gradle in vscode?

Viewed 165

I am trying to make a transition from Intellij to vscode at work. At the moment, we have tests written in Groovy (utilizing the Spock framework), Gradle as the build tool, and Junit as the runner.

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

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

In IntelliJ, it looks like this: enter image description here

I created a launch.json file in vscode that 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"
      ]
    }
  ]
}

But 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

This is my project tree

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

What am I missing here? Are they any additional arguments I need to provide to launch.json file to be able to run it?

I am running on a Macbook pro (Intel).

0 Answers
Related