Does testing support Spring 3.2 with Spock?

I am somewhat new to testing (scary, yes), so please forgive me if it is ignorant.

Is spock-spring 0.7-groovy -2.0 compatible with the new release of Spring 3.2 in light of changes to the testing framework?

Ive looked through Spring 3.2 docs in the Testing section :

Also like Spock docs in the News section :

But nothing helps me determine whether the new Spring 3.2 testing environment will test so that the test context for the Spock specification is configured as described for Spring 3.2. Testing (Spring 3.2 docs section 11.3.4) so ​​that my annotated beans are injected.

I tried anyway, but was unsuccessful in loading the testing context, although tests that are independent of the beans entered pass fine.

I can provide detailed information about my @ContextConfiguration attempts (I tried both the locations= and classes= templates in the Spring 3.2 docs section of 11.3.4 mentioned above) if it should work, but for now my question is just this : Can the Spock Specification testing context be configured to work with Spring 3.2 ?.

If so, any successful examples would be great (not seeing any Spring 3.2 with Spock around).

Thanks.

+4
source share
2 answers

As far as I can tell, Spock Spring integration should work just fine with the new testing features in Spring 3.2. Compared to testing Spring-based applications with JUnit, only the required changes (as always):

  • Delete @RunWith annotation
  • Put spock-spring on the test class path

Note that you cannot use the old approach to extend Spring base classes. Instead, you'll have to use the annotation-based Spring testing approach.

If you find a case where the strategy described above does not work (and you have the same test that works with JUnit), send a question to http://issues.spockframework.org .

+3
source

Inspired by Peter's answer, I found that the testing context is really set up. Here is what I used and it worked correctly:

PersonServiceSpec.groovy:

 @ContextConfiguration(locations="classpath*:/PersonServiceSpec-context.xml") class PersonServiceSpec extends Specification { @Autowired PersonService personService; def username def setup() { this.username = "tester" } def "Does search for username pull tester" () { expect: "tester" == username; } def "PersonService exists" () { expect: personService != null; } } 

with this PersonServiceSpec-context.xml placed in the classpath (src / main / resource for my maven proj):

 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="personSevice" class="<qualifiedname>.services.TPersonServiceImpl" > </bean> </beans> 

and the plastered class TPersonServiceImpl , which implemented my PersonService interface PersonService .

Passed the tests.

+1
source

All Articles