无法实例化规范'KernelTest'

时间:2015-03-19 10:40:50

标签: testing groovy gradle

我只尝试spock测试,并且“无法实例化规范'KernelTest'”,here是我的完整代码

以下是我的代码:

// build.gradle
apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.9'
    compile gradleApi()
    testCompile 'junit:junit:+'
    testCompile project(":ro")
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.3'
}

我的测试是:

// KernelTest.groovy

package ro.gd

class KernelTest extends spock.lang.Specification {
    def 'test smth'() {
        expect: 1 == 1

    }
}

它提出:

ro.gd.KernelTest > initializationError FAILED
    org.spockframework.util.InternalSpockError
        Caused by: java.lang.ExceptionInInitializerError at KernelTest.groovy:-1
            Caused by: groovy.lang.GroovyRuntimeException at KernelTest.groovy:-1

1 个答案:

答案 0 :(得分:0)

如果我将ro/build.gradle更改为使用特定版本的groovy,我可以使用最新的gradle:

compile 'org.codehaus.groovy:groovy-all:2.3.9'

然后将ro-gd/build.gradle的依赖关系更改为:

dependencies {
    compile gradleApi()
    testCompile project(":ro")
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.3', {
        exclude module: 'groovy-all'
    }
}