我正在爲Spock重寫一些JUnit測試以利用數據驅動的測試風格。Spock中的數據驅動測試
我正在努力與如何提供動態驗證。
這是我到目前爲止有:
def "domestic rules"(from, to, oneWay, check) {
expect:
String mealResponse = getMealResponse(new BookingOptions.BookingOptionsBuilder().setFrom(from).setTo(to).setOneWay(oneWay).build());
check(mealResponse)
where:
from | to | oneWay || check
'MNL' | 'PEK' | true || assertNoMeals()
}
def assertNoMeals = {
assert JsonAssert.with(it)
.assertThat('$.links', hasSize(1))
.assertThat('$.links[0].rel', is("http://localhost:9001/api/docs/rels/ink/meal-allocations"))
.assertThat('$.links[0].uri', startsWith("http://localhost:9001/api/tenants/acme/meals/allocations/"));
}
不幸的是,我在與數據的第一行線得到一個NullPointerException。
我想多數民衆贊成,因爲封閉運行在那一點,而不是剛剛宣佈。
有沒有辦法做得更好?
你應該閱讀[Spock Primer](http://spockframework.github.io/spock/docs/1.0/spock_primer.html)。你在斷言錯誤。 – Renato