
class MySpec extends spock.lang.Specification { def "My test"(int b) { given: def a = 1 expect: b > a where: b << 2..4 }} 抛出以下编译错误:“where-blocks只能包含参数化(例如’salary<< [1000,5000,9000]; salaryk = salary / 1000')” 但使用List而不是Range:
where: b << [2,3,4]
按预期编译并运行正常.
我还能以某种方式指定范围吗?
解决方法 使用where: b << (2..4)
测试也可以如下优化.注意测试没有参数.
def "My test"() { expect: b > a where: a = 1 b << (2..4)} 总结 以上是内存溢出为你收集整理的groovy – 如何在Spock规范的’where:’块中指定Range而不是List全部内容,希望文章能够帮你解决groovy – 如何在Spock规范的’where:’块中指定Range而不是List所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)