groovy – 如何在Spock规范的’where:’块中指定Range而不是List

groovy – 如何在Spock规范的’where:’块中指定Range而不是List,第1张

概述以下示例代码: class MySpec extends spock.lang.Specification { def "My test"(int b) { given: def a = 1 expect: b > a where: b << 2..4 }} 抛出以下编译错误:“w 以下示例代码:

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所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1234751.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存