我可以像这样进行测试并将where子句数据表提取到可重用块中吗?Spock:可重复使用的数据表
@Unroll
void "test that doSomething with #a and #b does not fail"(String a, String b) {
when:
doSomethingWithAandB(a, b)
then:
notThrown(Exception)
where:
a | b
"foo" | "bar"
"foo" | "baz"
"foo" | "foo"
}
是这样的(伪代码):
@Unroll
void "test that doSomethingElse with #a and #b does not fail"(String a, String b) {
when:
doSomethingElseWithAandB(a, b)
then:
notThrown(Exception)
where:
dataTable()
}
def dataTable(a, b) { // this is now reusable in multiple tests
a | b
"foo" | "bar"
"foo" | "baz"
"foo" | "foo"
}
看看这里:https://stackoverflow.com/questions/26156544/using-spock-data-table-for-filling-objects – Opal