Spock交互测试优先于异常

时间:2014-09-11 08:58:30

标签: java unit-testing groovy spock

为什么以下测试失败?"呼叫太少"而不是在调用模拟方法之前在do方法内抛出的实际异常?

有没有办法改变这种行为?

@Test
def "Should Create"() {
    when: "We do stuff"
    this.someStuff.do()

    then: "Should not get exception"
    notThrown(Exception)

    and: "Should send mail"
    1 * mailSession.send(_, _, _, _, _, _, _)
}

2 个答案:

答案 0 :(得分:2)

您发现了一个错误。请在http://issues.spockframework.org提交问题。

PS:使用notThrown(Exception)代替noExceptionThrown(),而不是1 * mailSession.send(_, _, _, _, _, _, _)。使用1 * mailSession.send(*_)更常见,而不是@Test。 {{1}}是一个JUnit注释,对Spock没有影响。

答案 1 :(得分:0)

do()方法中抛出的确切异常类型是什么?

您可能希望使用noExceptionThrown() Spock方法而不是notThrown(Exception)