Add Cucumber Features
After thinking about the requirements, it time to create the Cucumber feature files. And add them to the project.
To make it possible to run these Specification by Examples, Cucumber is used. The library Cucumber for Java Virtual Machine) contains the Java implementation.
Action Plan
- Add the required Cucumber dependencies.
-
Create directories for the Cucumber feature files and Cucumber step classes.
- Create directory for Cucumber step classes
mkdir src/it/java
-
Create directory for Cucumber feature file
mkdir src/it/resources
-
Add the new directories as Eclipse source Folders
Select both directoriesjava
andresources
and use the mouse menu: Build Path > Use as Source Folder - Add Maven failsafe plug-in to the Maven Project Configuration
pom.xml
WARNING The Maven failsafe plug-in is a general Integration Test plug-in, by default is scans for test classes with specific patterns. The classRunCucumberTests
does NOT fall in the pattern, so configuration is required. The Java test classes are not in a default Maven test classes directorysrc/test/java
, so configration is needed.
-
Create a Java package with a name similar as the package name in
src/main/java
.
The top level package name for the project iscom.github.<github-user>.mrrs
.
Create a new package name insrc/it/java
for the integration testscom.github.<github-user>.mrrs.it
.
Inside this Java package the Integration Test related classes will be added. -
Create a new class, in the package
com.github.<github-user>.mrrs.it
, that will run Cucumber feature files. Give this class a clear name likeRunCucumberTests
.
Install Cucumber for Eclipse feature
Use the Eclipse update site: http://cucumber.github.com/cucumber-eclipse/update-site
Create New Feature File
- Create the Cucumber feature file
room.feature
, in the directorysrc/it/resources
for the room features.
- Create a new class
RoomSteps
place it in the packagecom.github.<github-user>.mrrs.it.cucumber
.
This class will be used to place the Given, Then and When methods in, generated by Cucumber, based on the feature file.
Check the Set Up
Run Cucumber through Eclipse Cucumber
- Open the file
room.feature
. -
Use the right mouse button in the file editor, or on the file
room.feature
, in the view Project Explorer / Package Explorer. Use the menu: Run As > Cucumber Feature
This will show in the view Console, which Cucumber steps are still needed to be implemented.
Run Cucumber through Eclipse JUnit
TIP To just only run the Cucumber Examples, select the RunCucumberTests
class, from the view Package Explorer or Project Explorer and the use context menu: Run As -> JUnit Test