Java 斯波克交互测试优先于异常
为什么在调用模拟方法之前,以下测试失败的原因是“调用太少”,而不是在Java 斯波克交互测试优先于异常,java,unit-testing,groovy,spock,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.s
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(_, _, _, _, _, _, _)
}
do()
方法中引发的异常的确切类型是什么
您可能希望使用
noexceptionshown()
Spock方法,而不是notshown(Exception)
您发现了一个bug。请将问题提交至
PS:使用
noexceptionshown()
比使用noexceptionshown()
更常见,而不是notshown(Exception)
。使用1*mailSession.send(*/code>)比使用1*mailSession.send(*/code>)更常见,而不是1*mailSession.send(,,,,,,,,,,,,,,,{/code>)@Test
是一个JUnit注释,对Spock没有影响。信息太少,无法诊断它。现在还不确定,但我认为异常类型无关紧要。问题是,当抛出异常时,mailSession.send
不能被调用,因此“then”和“and”这两个部分都可以应用,但“Should send mail”优先。如果我把“应该发送邮件”这张支票收起来,那么“不应该得到例外”这一部分就得到了正确的处理。老实说,没有足够的详细信息公布出来。