Spock - Test Events Not Received, "NO-SOURCE"

Viewed 3067

I am getting an error "test events not received" when trying to run a basic Spock Test within my IDE. The issue seems to be due to :test NO-SOURCE. What am I missing?

Gradle output:

C:\Users\pc\IdeaProjects\schema-test>gradlew :cleanTest :test --tests com.scarlatti.SpockTest
:cleanTest UP-TO-DATE
:compileJava NO-SOURCE
:processResources
:classes
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:test NO-SOURCE

BUILD SUCCESSFUL

Project structure:

src
├───main
│   └───groovy
│      └───com
│          └───scarlatti
│               └───App.java
└───test
    └───groovy
        └───com
            └───scarlatti
                    SpockTest.groovy

build.gradle:

apply plugin: 'java'
apply plugin: 'idea'

repositories {
    mavenCentral()
}


dependencies {
    testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
    testCompile 'cglib:cglib-nodep:2.2'
}

Simple Spock test:

class SpockTest extends Specification {
    @Test
    "test that a spock test will run"() {
        when:
            println "running spock test..."
        then:
            notThrown(Exception)
    }
}
1 Answers

The problem lies in your build.gradle file.

Notice from the output that Gradle is only running the task :compileJava, but not :compileGroovy.

Spock test classes are written in Groovy, so no class com.scarlatti.SpockTest will be built unless you tell Gradle to run task :compileGroovy on build.

Solution:

  • include apply plugin: 'groovy' in build.gradle. This will attach the :compileGroovy task to Gradle's :test task graph.
  • include the org.codehaus.groovy:groovy-all:2.4.x jar in your compile dependencies. This allows Gradle to compile the Groovy code. Match the version of groovy to the version of Spock you are using.
Related