我想要找到的是,如果有一种方法可以识别在断言位于“with”内部时导致错误的特定断言。
理想情况下,我希望两种测试都能看到相同的特定结果。
给定测试的结果是:
Condition not satisfied: testInstance.with { trueParam falseParam } | | | false SpockSpec$TestMe@1cf4af1e at SpockSpec.Does not provides specific failure(SpockSpec.groovy:10) Condition not satisfied: testInstance.falseParam // expected to fail | | | false SpockSpec$TestMe@24c2ffbc at SpockSpec.Provides specific failure(SpockSpec.groovy:19)
代码:
import spock.lang.Specification
import spock.lang.Unroll
@Unroll
class SpockSpec extends Specification {
def testInstance = new TestMe(trueParam: true, falseParam: false)
def "Does not provides specific failure"() {
expect:
testInstance.with {
trueParam
falseParam
}
}
def "Provides specific failure"() {
expect:
testInstance.trueParam
testInstance.falseParam // expected to fail
}
class TestMe {
boolean trueParam, falseParam
}
}
答案 0 :(得分:2)
尝试
def "Does not provides specific failure"() {
expect:
with( testInstance ) {
trueParam
falseParam
}
}