使用 Spock 使用 Unroll 在测试名称中添加方法调用

Add method call in test name with Unroll using Spock

我有一个代码,我想把方法调用值放在方法的名称中。

        @Unroll
        def 'check #file other text'() {
        setup:
        def file = allProperties.keySet().getAt(0)
        ...
        where:
        ...

现在我创建了一个特殊的变量,其目的只是为了命名方法。我可以做类似的事情吗:

        static def allProperties
        def setupSpec(){
           allProperties== [1: 'asd', 2: 'ddd']
        }
        @Unroll
        def 'check #allProperties.keySet().getAt(0) other text'() {
        ....
        where:
        ...

已编辑:添加 setupSpec()

Unroll 支持 属性 访问或零参数方法。所以你可以拥有:

@Unroll
def "check #allProperties.keySet().first() other text"() { .. }

提供 allProperties 是 class 级变量或 @Shared 变量或在 where: 块中提到。