我做了一堆搜索,虽然我找到了一些结果,比如为什么 Spock 认为我的数据提供者没有数据?,它们似乎都不是很有帮助。
我只做过几次数据提供者,但这似乎很完美。我有以下静态方法:
static List<ContactPointType> getAddressTypes() {
List<ContactPointType> result = new ArrayList<>();
for (ContactPointType cpType : ContactPointType.values()) {
if (cpType.toString().endsWith("Addr")) {
result.add(cpType);
}
}
return result;
}
然后我试图将它用作数据提供者来调用我的类上的函数:
@Unroll("#cpType should be address")
def "isAddress addresses"() {
expect: "isAddress() to be true"
contactPoint.isAddress(cpType)
where:
cpType << getAddressTypes()
}
当我运行它时,我得到:
org.spockframework.runtime.SpockExecutionException: Data provider has no data
at org.spockframework.runtime.JUnitSupervisor.afterFeature(JUnitSupervisor.java:191)
at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:236)
就像我说的,这似乎很简单。有没有人有任何想法?