Spock Spring runner fails to run tests if environment has a bean factory with InjectionPoint #676

Open
rvaleev opened this Issue Dec 8, 2016 · 0 comments

Projects

None yet

1 participant

@rvaleev
rvaleev commented Dec 8, 2016

Issue description

When I run Spock Spring test in environment what has a bean factory with InjectionPoint it fails to start.
It should be able to exclude such a bean.

WARNING: Caught exception while allowing TestExecutionListener [org.spockframework.spring.SpringMockTestExecutionListener@3569edd5] to process 'before' execution of test method [public void com.xxx.services.MyServiceSpec.$spock_feature_0_0()] for test instance [com.xxx.services.MyServiceSpec@1f651cd8] java.lang.IllegalStateException: No current InjectionPoint available for method 'createMyService' parameter 0 at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:831) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) at org.spockframework.spring.SpringMockTestExecutionListener.beforeTestMethod(SpringMockTestExecutionListener.java:50) at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:269) at org.spockframework.spring.SpringTestContextManager.beforeTestMethod(SpringTestContextManager.java:54) at org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:45) at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:28) at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87) at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:472) at org.spockframework.runtime.BaseSpecRunner.runSetup(BaseSpecRunner.java:375) at org.spockframework.runtime.BaseSpecRunner.runSetup(BaseSpecRunner.java:370) at org.spockframework.runtime.BaseSpecRunner.doRunIteration(BaseSpecRunner.java:323) at org.spockframework.runtime.BaseSpecRunner$6.invoke(BaseSpecRunner.java:309) at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481) at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464) at org.spockframework.runtime.BaseSpecRunner.runIteration(BaseSpecRunner.java:288) at org.spockframework.runtime.BaseSpecRunner.initializeAndRunIteration(BaseSpecRunner.java:278) at org.spockframework.runtime.BaseSpecRunner.runSimpleFeature(BaseSpecRunner.java:269) at org.spockframework.runtime.BaseSpecRunner.doRunFeature(BaseSpecRunner.java:263) at org.spockframework.runtime.BaseSpecRunner$5.invoke(BaseSpecRunner.java:246) at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481) at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464) at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:238) at org.spockframework.runtime.BaseSpecRunner.runFeatures(BaseSpecRunner.java:188) at org.spockframework.runtime.BaseSpecRunner.doRunSpec(BaseSpecRunner.java:98) at org.spockframework.runtime.BaseSpecRunner$1.invoke(BaseSpecRunner.java:84) at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481) at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464) at org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:76) at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:67) at org.spockframework.runtime.Sputnik.run(Sputnik.java:63) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

How to reproduce

  1. Create a Spring configuration(MyConfig) with a bean factory similar to:

@Bean @Scope("prototype") MyService createMyService(InjectionPoint injectionPoint) { .... }
2. Run a test:

@ContextConfiguration(classes = MyConfig.class) class MyServiceSpec extends Specification { def "spring test" () { }

Additional Environment information

Java/JDK

1.8.0_65

Groovy version

2.4.7

Build tool version

Apache Maven

3.3.9

Operating System

Ubuntu

IDE

IntelliJ

Build-tool dependencies used

Apache Maven

        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>1.1-groovy-2.4-rc-3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-spring</artifactId>
            <version>1.1-groovy-2.4-rc-3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.7</version>
            <scope>test</scope>
        </dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment