testing - 无法实例化规范 'KernelTest'

标签 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

最佳答案

如果将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'
    }
}

关于testing - 无法实例化规范 'KernelTest',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29142377/

相关文章:

spring-boot - 将 gradle 多项目转换为 springboot fat jar 应用程序

node.js - 是否可以测试 Jest 测试?

testing - 软件开发测试人员

java - 测量远程脚本测试的代码覆盖率

java - Groovy/Java 在 Windows 机器上获取用户变量

groovy - 如何获取 Gradle 子项目的拓扑排序列表?

grails - find 和 findAll 在 grails 2.1.1/groovy 1.8.8 中不起作用

gradle - sqljdbc4-4.0.jar的Gradle依赖关系

docker - 公开在gitlab ci docker镜像中运行的服务器

api - 为 REST API 编写单元测试的最佳方式是什么?