Skip to content

IDE support

jarbarker edited this page · 30 revisions
Clone this wiki locally

For a list of features and what IDEs support which ones, see this public google spreadsheet.

At the time of this writing (30 October 2012) Cucumber-JVM is natively supported by IDEA IntelliJ 12.

Please file bugs and feature requests in the IDEA project and Cucumber JVM component at youtrack.jetbrains.com.

This page exists primarily to help IDE vendors implement support for it. Consider it a wish-list.

A lot of these features are already implemented in the excellent RubyMine, but this focuses on Ruby only. We want these great features for Cucumber-JVM - in IntelliJ IDEA and Eclipse!

Running Feature files directly with Eclipse:

1: Right click on the feature file and select "Debug As" or "Run As"

Create a new "Java Application" execution.

2: Under the "Main" tab....

2.1 It should have your Project name in the "Project:" field.... TODO: test replacing with a system prop for the currently selected files project* 2.2 Enter "cucumber.api.cli.Main" without quotes for the "Main class" field..

3: Under the tab for "Arguments"

3.1 For "Program Arguments", enter...

${selected_resource_loc}
--glue com.your.glue.location
--plugin pretty
--monochrome

This will allow any selected feature file to be run, and ensure useful logging is sent to the IDE's console. Note that Eclipse's console does not support ANSI color (and delete prior line) console colors.

3.2 Under "VM Arguments..."

-ea

if you want to pass in system parameters, do so here:

-DtargetAppType=MobileWebApp

This will turn on java assert() statements, which is need to allow the Then steps to throw assertion exceptions if the code a test is testing is broken.

STEPS 1 - 3 will be saved so you will not have to repeat them again.

4. Click the "Run" or "Debug" button.

Running Feature files directly with IDEA (up to IntelliJ 11, since IntelliJ 12 supports cucumber-jvm natively)

There are two possible ways to run the application in IDEA

  1. One is running the selected feature file via an "external tool", that tool happens to be java... more in a second.
  2. The other way is run the the test as via a main method with run/debug as application functionality.

The trade offs:

  • When running an external tool you can not (easily) debug the test.
  • When running as a java main method you will have to type in the feature file name... very annoying.

Recommendation: run as an external tool when running tests, and debug as a main method application as your about to go through a very annoying process anyway.

Configuring External tool execution in IDEA:

  1. Open "Settings"
  2. Under "External Tools" menu
  3. Click "add"
  4. On the "Edit Tool" enter the following values with out quotes for each field
    • Name: "Run"
    • Group: "Cucumber"
    • Description: "Cucumber"
    • Program: "$JDKPath$/bin/java" (reverse the slashes on windows, maybe leave quotes if spaces in path)
    • Parameters: "-cp $Classpath$:$OutputPath$ cucumber.api.cli.Main $FilePath$ --glue your.glue.path --format gherkin.formatter.PrettyFormatter" (replace : with ; on windows and add "" around $Classpath$:$OutputPath$)
    • Working Directory: "$ModuleFileDir$/target" (reverse the slash on windows)
  5. Press Save

    Now you can right click on any *.feature file and click on the "Cucumber" -> "Run" menu and you will run that test.

Configuring Application run in IDEA:

  1. Under the "Run" menu select "Edit Configuration..."
  2. On the "Run/Debug Window"
  3. Cick the "+" button and select "Application"
  4. For the following field the the values without quotes
    • Name: "Cucumber"
    • Main method: "cucumber.api.cli.Main"
    • VM Options: "-ea"
    • Program Arguments: "$FilePath$ --glue com.your.gluecode.path --format gherkin.formatter.PrettyFormatter"
    • Working Directory: "$MODULE_DIR$/target/" (reverse the slashes on windows)
    • Use classpath of Module: Make sure your module is selected...

You may also pass system properties in the VM Arguements section with -D parameters like -DtargetAppType=MobileWebApp

The problem with this approach:

You will have to replace the $FilePath$ with the actual full path of your feature file.

Then you will be able to debug the test.

If you are using IntelliJ IDEA, consider voting for IDEA-81672.

Run features and scenarios with JUnit

It's currently possible to run features and scenarios from an IDE via JUnit:

import cucumber.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class RunCukesTest {
}

This will run all Cucumber features, but if you want to run a single scenario you have to edit the Java class to add tags, line numbers or names. For example:

@RunWith(Cucumber.class)
@Cucumber.Options(paths={"my/super.feature:34"})

or:

@RunWith(Cucumber.class)
@Cucumber.Options(tags={"@hello"})

A better way would be to open a feature in the IDE, place the cursor on the scenario you want to run, and press a key combination to run it (CTRL-SHIFT-F10 in IDEA for example).

Something went wrong with that request. Please try again.