Spock MissingMethodException

时间:2013-11-12 13:32:29

标签: testing groovy spock

我的东西看起来像是类似的规范:

def "my spec"(Record record) {
    given: 
        Something something = getSomething()
    and: 
        otherThing = getOtherThing()

    doFlow(something, record)
    if (record.someType = Types.SOME_SPECIFIC_TYPE) {
        doFlow(something, record)
    } 
}

def doFlow(Something something, Record record) {
    when:
         //code
    then:
         //asserts

    when:
         //code
    and: 
         //mode code
    then:
         //code
}

但是,在运行时,我得到:groovy.lang.MissingMethodException: No signature of method doFlow() is applicable for arguments Something, Record values: [given values]

1 个答案:

答案 0 :(得分:6)

“my flow”和“doFlow”都是功能方法,因为它们包含givenwhenthen等块。 Spock负责调用特征方法,而一个特征方法不能调用另一个特征方法。如果doFlow是一个帮助方法,它应该使用显式assert语句,并且不应该有任何块。

PS:功能方法不能声明方法参数,除非它们是数据驱动的(即有一个where块)。

PPS:功能方法不能只有given / and块。 (你会得到一个编译错误。)

相关问题