首页 > 解决方案 > MissingMethodException:没有方法签名:org.spockframework.mock.runtime.InteractionBuilder.setArgListKind()

问题描述

我在任何地方都找不到描述的这个问题,所以我为其他发现这个问题的人发帖。

我发现使用 '>>' 或 '>>>' 运行 spock 存根的任何示例都失败,并出现相同的异常。 MissingMethodException: No signature of method: org.spockframework.mock.runtime.InteractionBuilder.setArgListKind() is applicable for argument types: (Boolean, Boolean) values: [true, false]

例如,来自Javitar:Spock 测试 – Spock 教程

def "should return Role.USER when asked for role"() {
        given:
        List list = Stub()
        list.size() >> 3
        expect:
        // let's see if this works
        list.size() == 3
    }

标签: intellij-ideamockingspockstubbing

解决方案


我正在运行:spockVersion=1.3-groovy-2.5

Intellij 使用 Junit 模板运行 Spock 测试。我在这里找到了解决方案: 结合 Spock 1.2 和 Junit 5 测试 解决方案是将以下内容添加到我的 build.gradle 中:

dependencies {
    implementation "org.junit.jupiter:junit-jupiter-api:5.6.1"
    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.6.1"
}

test { // only needed if doing 'gradle test' 
    useJUnitPlatform()
}

我在 Intellij/Idea 2019.3 中运行此代码,使用

------------------------------------------------------------
Gradle 6.2.2
------------------------------------------------------------

Build time:   2020-03-04 08:49:31 UTC
Revision:     7d0bf6dcb46c143bcc3b7a0fa40a8e5ca28e5856

Kotlin:       1.3.61
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_152 (Azul Systems, Inc. 25.152-b16)
OS:           Linux 4.15.0-52-generic amd64
Linux Mint 19 Tara

推荐阅读