New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection of data in data-driven methods is broken #651

Open
Vampire opened this Issue Sep 26, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@Vampire
Contributor

Vampire commented Sep 26, 2016

Having the specification

class TestSpecification extends Specification {
    @Unroll
    def 'test1 | a = #a | b = #b'() {
        given:
        println "a = $a"
        println "b = $b"

        expect:
        a in ['a1', 'a2']
        b in ['b1', 'b2']

        where:
        a << ['a1', 'a2']
        b << ['b1', 'b2']
    }

    @Unroll
    def 'test2 | a = #a | b = #b'(a, b) {
        given:
        println "a = $a"
        println "b = $b"

        expect:
        a in ['a1', 'a2']
        b in ['b1', 'b2']

        where:
        a << ['a1', 'a2']
        b << ['b1', 'b2']
    }

    @Unroll
    def 'test3 | a = #a | b = #b'(b, a) {
        given:
        println "a = $a"
        println "b = $b"

        expect:
        a in ['a1', 'a2']
        b in ['b1', 'b2']

        where:
        a << ['a1', 'a2']
        b << ['b1', 'b2']
    }
}

test3 will fail.

With spock 1.0 you get

TestSpecification > test3 | a = b1 | b = a1 FAILED
    org.spockframework.runtime.ConditionNotSatisfiedError at TestSpecification.groovy:42

TestSpecification > test3 | a = b2 | b = a2 FAILED
    org.spockframework.runtime.ConditionNotSatisfiedError at TestSpecification.groovy:42

and in the report

test3 | a = b1 | b = a1

Condition not satisfied:

a in ['a1', 'a2']
| |
| false
b1

    at TestSpecification.test3 | a = #a | b = #b(TestSpecification.groovy:42)

test3 | a = b2 | b = a2

Condition not satisfied:

a in ['a1', 'a2']
| |
| false
b2

    at TestSpecification.test3 | a = #a | b = #b(TestSpecification.groovy:42)

because the variables are injected in order, not by name.

With spock 1.1 it is even worse, because you get

TestSpecification > test3 | a = #a | b = #b FAILED
    java.lang.IllegalArgumentException

and in the report

test3 | a = #a | b = #b

java.lang.IllegalArgumentException: Method '$spock_feature_0_2prov0([])' can't be called with parameters '[null]'!
    at org.spockframework.util.ReflectionUtil.validateArguments(ReflectionUtil.java:186)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:173)
    at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:377)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment