Unexpected behaviour when Spock datatable's header contains variable named like variable in the other feature method

允我心安 提交于 2021-01-27 20:40:29

问题


I have a problem with data-driven tests in Spock. When datatable header contains variable (in this case 'b') named like variable in the other feature method, the following exception is thrown:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '3' with class 'java.lang.Integer' to class 'java.util.UUID'

Example specification class:


class ExampleSpec extends Specification {

    def 'example feature with variable named like datatable header'() {
        given:
        UUID b = UUID.randomUUID()

        when:
        def length = b.toString().length()

        then:
        length == 36
    }

    def "maximum of two numbers"() {
        expect:
        Math.max(a, b) == c

        where:
        a | b | c
        1 | 3 | 3
        0 | 0 | 0
    }
}

Does anyone know what the reason is that datatable's header variable interferes in such an unexpected way with a variable defined in the previous feature method?

The problem occurs only in version: '1.x-groovy-2.5'.

来源:https://stackoverflow.com/questions/58489784/unexpected-behaviour-when-spock-datatables-header-contains-variable-named-like

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!