jtanistra / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

No access to @Autowired variables in setupSpec() when using Spring's ContextConfiguration #145

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
A spec that is annotated with @ContextConfiguration and uses @Autowired/@Inject 
cannot access those injected beans in the setupSpec() or cleanupSpec() methods 
because they just yield null.

reference example: 
http://code.google.com/p/spock/source/browse/trunk/spock-spring/src/test/groovy/
org/spockframework/spring/TransactionalExample.groovy

as discussed in:
http://groups.google.com/group/spockframework/browse_thread/thread/22e15161529ba
ce

Original issue reported on code.google.com by stephan....@gmail.com on 16 Nov 2010 at 11:32

GoogleCodeExporter commented 8 years ago
please fix this. This is really annoying

Original comment by belov...@gmail.com on 12 May 2012 at 9:09

GoogleCodeExporter commented 8 years ago
The behavior is a consequence of the design of Spring's TestContext framework. 
I don't see a way to change it without hitting other problems. The situation 
isn't any different when using the TestContext framework with JUnit.

A @SetupOnce extension that runs before the first feature method of a spec 
class might be an effective way to overcome this problem. I'll think about 
that. Meanwhile you can write one yourself, or use one of the easier 
workarounds outlined in the links provided by the original author of this issue.

Original comment by pnied...@gmail.com on 12 May 2012 at 9:43