鉴于我想用两个参数测试我的方法:一个应该导致成功,另一个应该导致异常。
写一些像......
when:
myObject.myMethod(value);
then:
result
where:
value | result
new Good() | notThrown(Exception)
new Bad() | thrown(Exception)
..在Spock中是不可能的。
如何修复它并避免编写两个单独的功能方法?
答案 0 :(得分:0)
import spock.lang.*
class MyFirstSpec extends Specification {
def "let's try this!"() {
when:
new Test().method('Good')
then:
noExceptionThrown()
when:
new Test().method('Bad')
then:
thrown(Exception)
}
class Test {
def method(String param) {
if(param == 'Good') {
return param
}
throw new Exception()
}
}
}
测试here