-
Notifications
You must be signed in to change notification settings - Fork 72
Maven
The Cuke4Duke Maven plugins lets you run Cucumber features with Maven. All of Cuke4Duke’s examples have a pom.xml
that you can use for inspiration, but we’ll walk you through the details on this page.
To make Cucumber work with your Maven project you must add the following to your pom.xml
file:
Tell Maven where to download cuke4duke and jruby:
<repositories> <repository> <id>codehaus</id> <url>http://repository.codehaus.org</url> </repository> <repository> <id>cukes</id> <url>http://cukes.info/maven</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>cukes</id> <url>http://cukes.info/maven</url> </pluginRepository> </pluginRepositories>
Tell Maven that you’re using Cuke4Duke and PicoContainer so that Maven will add them to your Classpath. (If you’re using Spring you can specify that instead of PicoContainer). We also add a dependency to JUnit because our Java step definitions will use it.
<dependencies> <dependency> <groupId>cuke4duke</groupId> <artifactId>cuke4duke</artifactId> <version>0.1.4</version> <scope>test</scope> </dependency> <dependency> <groupId>org.picocontainer</groupId> <artifactId>picocontainer</artifactId> <version>2.8</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.5</version> <scope>test</scope> </dependency> </dependencies>
Tell Maven to run your Cucumber features during the integration-test
phase:
<build> <plugins> <plugin> <groupId>cuke4duke</groupId> <artifactId>cuke4duke-maven-plugin</artifactId> <configuration> <jvmArgs> <jvmArg> -Dcuke4duke.objectFactory=cuke4duke.internal.java.PicoFactory </jvmArg> </jvmArgs> <cucumberArgs> <cucumberArg>${basedir}/src/test/java</cucumberArg> </cucumberArgs> <gems> <gem>cucumber</gem> </gems> </configuration> <executions> <execution> <id>run-features</id> <phase>integration-test</phase> <goals> <goal>cucumber</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Before you can use Cuke4Duke with Maven, you must install the Cucumber Ruby gem (and all of its dependent Ruby gems) in JRuby:
mvn -Dcucumber.installGems=true cuke4duke:cucumber
Your application’s Cucumber Feature files should be placed in a directory named features
– just like on any other Cucumber project. This is where the Cuke4Duke Maven plugin will expect them to be.
The Pure java step definitions should be placed where you would normally place JUnit tests – in src/test/java
. Make sure you also pass --require target/test-classes
to cucumber in your pom.xml.
If you use one of cuke4duke’s languages that doesn’t have to be precompiled (such as Groovy or Clojure), just put step definitions under features/step_definitions
. In this case you don’t have to use the --require
option.
Now that you have configured your POM and created some features and step definitions, try running your features:
If you want to recompile your code and step definitions:
mvn integration-test
or if you don’t want to recompile (for example if you only modified a .feature file, or an interpreted step definition file):
mvn cuke4duke:cucumber