Unable to run Spock tests after upgrading to 2.0
Asked Answered
F

0

1

I'm trying to upgrade a Spring Boot (2.1.4.RELEASE) project from Spock 1.3 to 2.0. Unfortunately, I'm getting No tests found for given includes: for any test I try to run. Here is a build.gradle snippet with what I hope are all the relevant parts:

testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'

// enabling spock - the bdd
testImplementation(
    "org.spockframework:spock-core",
    "org.spockframework:spock-spring:${spockGroovyVersion}",
    "org.codehaus.groovy:groovy:3.0.8",
    "io.github.http-builder-ng:http-builder-ng-apache:1.0.4",
    platform("org.spockframework:spock-bom:${spockGroovyVersion}")
)

// Provides JUnit, Spring Test, AssertJ, Hamcrest, Mockito, JSONassert, & JsonPath
testImplementation("org.springframework.boot:spring-boot-starter-test") {
    // don't include JUnit 4 (needed until spring-boot-starter-test:2.2.0 is supported)
    exclude group: 'junit', module: 'junit'
}

test {
    useJUnitPlatform()
}

I get the same result whether useJUnitPlatform() is present or commented out.

Fant answered 19/7, 2021 at 19:40 Comment(6)
I assume, ${spockGroovyVersion} is exactly 2.0-groovy-3.0? BTW, you do need useJUnitPlatform() for Spock 2, please do not comment it out. An MCVE reproducing the problem on GitHub would be helpful.Platinotype
BTW, do you have plugins { id 'java'; id 'groovy' } in your Gradle config? Without the Groovy plugin, no tests can be found.Platinotype
I also just remember that I saw the same error before, when using something like sourceCompatibility = '11', but running the build on an older JDK like 8. I just updated my answer here. If that solves your problem, please let me know.Platinotype
Ah, yes, I missed that one variable. It is indeed exactly 2.0-groovy-3.0. I am unfortunately unable to provide an MCVE as this is a work project, and it could well take longer to disentangle unrelated code than to stumble upon a fix without an MCVE. With respect to plugins, I have apply plugin: 'groovy', no Java plugin. The only Java version line I see is javaConfig.targetVersion = JavaVersion.VERSION_1_8Fant
Then you should have said "would be required" rather than "would be helpful".Fant
@Fant take a look at github.com/spockframework/spock-example and try to compare it to your project.Publicness

© 2022 - 2024 — McMap. All rights reserved.