加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 16:29:53 所属栏目:大数据 来源:网络整理
导读:以下示例代码: 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')”
以下示例代码:

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)
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读