Search code examples
javagradlegrailsspock

Grails - Spock - excution failed for task ':test' - Gradle


I am using Grails + groovy with Spock. The application was building fine till I installed Spock and started writing unit test.

JVM version - 1.8.0_171***Grails version - 3.3.6***Groovy version - 2.4.15

Dependencies -

testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails:grails-web-testing-support"
testCompile "org.grails.plugins:geb:1.1.2"
testCompile "org.spockframework:spock-core:1.1-groovy-2.4-rc-2"
testCompile "org.grails:grails-test-mixins:3.3.0.RC1"  

I tried "clean" and "Invalidate caches / restart" in IntelliJ(ultimate) too.

Build failed with an exception

Initialization Error

unit test code


Solution

  • Looks like a version problem to me. Also, use ControllerUnitTest trait instead of test mixin. So start with removing these lines from build.gradle.

    testCompile "org.spockframework:spock-core:1.1-groovy-2.4-rc-2"
    testCompile "org.grails:grails-test-mixins:3.3.0.RC1"  
    

    Then update the test to implement ControllerUnitTest trait. Here is an example.

    You should also check the documentation.