【问题标题】:Spock MissingMethodExceptionSpock MissingMethodException
【发布时间】:2013-11-12 13:32:29
【问题描述】:

我有类似规格的东西:

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]

【问题讨论】:

  • 大概这之后是寻找Spock的失踪方法。 :-)

标签: testing groovy spock


【解决方案1】:

“我的流程”和“doFlow”都是特征方法,因为它们具有 givenwhenthen 等块。调用特性方法是 Spock 的职责,一个特性方法不能调用另一个。如果doFlow 是一个辅助方法,它应该使用显式的assert 语句,并且不应该有任何块。

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

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

【讨论】:

  • 还有没有注释说Spock这只是一个简单的方法而不是一个特征方法?
  • 一种简单的方法是没有块及其附带的功能。不支持您要求的功能的原因是不清楚从另一个方法的 when 块调用具有 expect 块的方法意味着什么。突然之间,when 块将不再实现其(仅)执行被测代码的目的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
相关资源
最近更新 更多