我怎样才能重复Spock测试?

fed*_*lov 6 grails spock

如此处所述, @Repeat现在不支持注释.我怎样才能将spock测试标记为重复n次?

假设我有spock测试:

def "testing somthing"() {
    expect:
    assert myService.getResult(x) == y

    where:
    x | y
    5 | 7
    10 | 12
}
Run Code Online (Sandbox Code Playgroud)

如何将其标记为重复n次?

Tom*_*ski 6

您可以使用如下@Unroll注释:

@Unroll("test repeated #i time")
def "test repeated"() {
    expect:
        println i
    where:
        i << (1..10)
}
Run Code Online (Sandbox Code Playgroud)

它将为您创建10个独立的测试。

编辑完问题后,请使用EDIT进行编辑:

def "testing somthing"() {
    expect:
        assert myService.getResult(x) == y

    where:
        x | y
        5 | 7
        5 | 7
        5 | 7
        5 | 7
        5 | 7
        10 | 12
        10 | 12
        10 | 12
        10 | 12
        10 | 12
Run Code Online (Sandbox Code Playgroud)

}

这是目前在spock中执行此操作的唯一方法。


Pet*_*ser 1

您可以使用 where 块,如上面的答案所示。目前无法重复已经具有 where 块的方法。