Having stumbled on cuke4duke after it had become deprecated in favor
of cucumber-jvm, I had a bit more manual work to do, but as of this
afternoon, have spring injection playing nicely. I did a local
conversion of the java-calculator example that works via Spring.
Basic steps:
1) Swap spring for pico container (test scope caused transitive
dependency fun w/ spring framework stuff, so went back to default
scope!):
<!--
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${project.version}</version>
<!-- <scope>test</scope> -->
</dependency>
2) Add a cucumber.xml in src/test/resources:
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="
http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="cucumber.examples.java"/>
</beans>
3) Replaced inline instantiation of RpnCalculator in two stepdef java
files to use Spring @Autowired:
@Autowired
private RpnCalculator calc;
4) Set up RpnCalculator for detection by spring context scanning (note
prototype scope...w/o that, Shopping steps fail due to the stageful
nature of RpnCalculator and leftover data from prior scenarios!)
@Component
@Scope("prototype")
public class RpnCalculator
.
.
.
With those pieces in play, it works like a charm, running features
thru JUnit (in Eclipse...nice feature/scenario output) or through
command line mvn test call (less helpful/self-documenting output).
Enjoy!
PWM