groovyspockunroll

Add method call in test name with Unroll using Spock


I have a code and I want to put method invocation value in the name of the method.

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

Now I create special variable which purpose is only for naming the method. Can I do something like:

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

Edited: Add setupSpec()


Solution

  • Unroll supports property access or zero-arg methods. So you can have:

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

    provided allProperties is a class level variable or @Shared variable or mentioned under where: block.