Want to jump right in? I have zipped up a working project, with examples. You can download it here.
What’s that? You like using Cucumber and want to use it with your Java project but your company ecosystem is not hip to JRuby? Enter the cukes4duke project, which allows you to run cucumber with most JVM-based languages. I am focusing on running it with the Maven plugin. This tutorial assumes you have maven installed, and Java knowledge.
Before you start, you must run the following goal. It will install JRuby and the gems to your .m2 repository.
Next, create a feature file under the ‘features’ directory (at the root of your project).
features/example.feature:
Feature: Example of a feature file
As some aspiring cuke4duke user
I want an example of how it works
So that I can easily setup my project to use it
# This should pass
Scenario: A simple passing scenario
Given the letter 'A'
When I check the letter
Then the letter should be 'A'
Then, create a ’step’ class under src/test/java/cukes:
src/test/java/cukes/CukeSteps.java:
package cukes;
import cuke4duke.annotation.I18n.EN.Given;
import cuke4duke.annotation.I18n.EN.Then;
import cuke4duke.annotation.I18n.EN.When;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
public class CukeSteps {
private char theLetter;
@Given("^the letter '([A-Za-z])'$")
public void gimmeALetter(final char theLetter) {
this.theLetter = theLetter;
}
@When("^I check the letter(?:s)?$")
public void checkThem() {
// just a stub
}
@Then("^the letter should be '([A-Za-z])'$")
public void checkTheLetter(final char aLetter) {
assertThat(theLetter, is(aLetter));
}
}
Now, run that test using:
mvn integration-test
I have zipped up an example project with more example steps. It is located here.
Kerry is a technical consultant, web enthusiast, and loving father of two boys. He has experience with a
wide variety of technologies across multiple platforms.