Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.
aslakhellesoy edited this page May 25, 2011 · 11 revisions

Spring integration

If the application you are developing is using the Spring framework, Cuke4duke can help you by autowiring spring beans into your Java step definitions. Enabling Spring is done with a JVM argument:

-Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.SpringFactory

This can be passed via Ant, Maven or the Command Line.

You also need to provide a Spring configuration for the environment you want cuke4duke to run and make sure cuke4duke autodetects the Spring-enabled Step Definitions. This last step is performed by adding the snippet below to your configuration, or in a seperate context file loaded by Cuke4Duke:

<beans> <!-- XML declarations and namespaces omitted for brevity -->
  <context:component-scan base-package="mypackage" >
    <context:include-filter
      type="annotation" 
      expression="cuke4duke.spring.StepDefinitions"/>
  </context:component-scan>
  <import resource="context.xml"/>
</beans>

If you name this file cucumber.xml and it’s available on the classpath, Cuke4Duke will pick it up automatically. If you choose to name it differently you can tell Cuke4Duke where to find it with a JVM argument:

-Dcuke4duke.springXml=something_else.xml

Step Definitions can be written just like regular Java step definitions – with some extra annotations:

package race;
import cuke4duke.spring.StepDefinitions
import org.springframework.beans.factory.annotation.Autowired;

@StepDefinitions
public class RaceSteps {
    @Autowired
    private DriverService driverService
    // Pure Java Step definitions to follow...
}

Check out the Spring example for a full example.

Clone this wiki locally