Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

This is the simplest possible setup for Cucumber-JVM using Java.

Notifications You must be signed in to change notification settings

testdouble/java-cucumber-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-cucumber-example

A sample project for Cucumber and/or Selenium tests.

Instructions

Clone the repo:

Git:

$ git clone [email protected]:testdouble/java-cucumber-example.git

Svn:

$ svn co https://github.com/testdouble/java-cucumber-example

Or download a ZIP of master manually and expand the contents someplace on your system

Prerequisites

In order to run browser tests, Selenium will need to be able to drive a browser installed to your system.

(TODO after testing on Windows)

Verify installation

Use Maven

Open a command window and run:

mvn test

This runs Cucumber features using Cucumber's JUnit runner. The @RunWith(Cucumber.class) annotation on the RunCukesTest class tells JUnit to kick off Cucumber.

Use Ant

Open a command window and run:

ant download
ant runcukes

This runs Cucumber features using Cucumber's Command Line Interface (CLI) runner. Note that the RunCukesTest junit class is not used at all. If you remove it (and the cucumber-junit jar dependency), it will run just the same.

Overriding options

The Cucumber runtime parses command line options to know what features to run, where the glue code lives, what plugins to use etc. When you use the JUnit runner, these options are generated from the @CucumberOptions annotation on your test.

Sometimes it can be useful to override these options without changing or recompiling the JUnit class. This can be done with the cucumber.options system property. The general form is:

Using Maven:

mvn -Dcucumber.options="..." test

Using Ant:

JAVA_OPTIONS='-Dcucumber.options="..."' ant runcukes

Let's look at some things you can do with cucumber.options. Try this:

-Dcucumber.options="--help"

That should list all the available options.

IMPORTANT

When you override options with -Dcucumber.options, you will completely override whatever options are hard-coded in your @CucumberOptions or in the script calling cucumber.api.cli.Main. There is one exception to this rule, and that is the --plugin option. This will not override, but add a plugin. The reason for this is to make it easier for 3rd party tools (such as Cucumber Pro) to automatically configure additional plugins by appending arguments to a cucumber.properties file.

Run a subset of Features or Scenarios

Specify a particular scenario by line (and use the pretty plugin, which prints the scenario back)

-Dcucumber.options="classpath:skeleton/belly.feature:4 --plugin pretty"

This works because Maven puts ./src/test/resources on your classpath. You can also specify files to run by filesystem path:

-Dcucumber.options="src/test/resources/skeleton/belly.feature:4 --plugin pretty"

You can also specify what to run by tag:

-Dcucumber.options="--tags @bar --plugin pretty"

Running only the scenarios that failed in the previous run

-Dcucumber.options="@target/rerun.txt"

This works as long as you have the rerun formatter enabled.

Specify a different formatter:

For example a JUnit formatter:

-Dcucumber.options="--plugin junit:target/cucumber-junit-report.xml"

About

This is the simplest possible setup for Cucumber-JVM using Java.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 89.8%
  • Gherkin 10.2%