IntelliJ IDEA 2020.3 Help

Run Cucumber tests

The quickest way of running Cucumber tests is by using the icons in the gutter next to the necessary feature or scenario. The icons change depending on the state of your test: Run Test marks new tests; the Run test icon marks successful tests; the Rerun the Run button icon marks failed tests.

Run a scenario

  • Click Run Test in the gutter next to the scenario that you want to run and select Run 'Scenario: <name>'.

    You can also place the caret at Scenario and press Ctrl+Shift+F10 .

    Running a scenario using the gutter icon

Run a feature

  • Click Run Test in the gutter next to the feature that you want to run and select Run 'Feature: <name>'.

    You can also place the caret at Feature and press Ctrl+Shift+F10 .

    Running a feature using the gutter icon
  • In the Project tool window ( Alt+1 ), right-click a feature file and select Run Feature <name>.

Run all feature files in a folder

  • In the Project tool window ( Alt+1 ), right-click the features folder and select Run all Features in: <directory name>.

    If there are other testing frameworks in your project, the IDE will prompt you to select how you want to run your tests: as Cucumber features or as tests of another framework.

    Running all features in the features folder

When the tests finish running, the results are displayed on the Test Runner tab of the Run tool window. On this tab, you can rerun tests, export and import test results, see how much time it took to run each test, and so on. For more information, refer to Explore test results.

Test results displayed in the Test Runner tab

Run Cucumber tests with JUnit

In IntelliJ IDEA, you can use JUnit to run Cucumber tests.

To run JUnit, add the cucumber-junit dependency to your project. If you're using JUnit 5, add the junit-vintage-engine dependency as well.

  1. In the Project tool window, right-click the package with step definitions and select New | Java Class.

  2. Name the new class (for example, RunCucumberTest) and press Enter .

  3. Add the following code to the class:

    import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features = {"classpath:features/BeerCans.feature"}, glue = {"com.examples.cucumber"}) public class RunCucumberTest { }

    In @CucumberOptions, specify the .feature file and the package with step definitions in your project (Glue).

  4. Click Run Test in the gutter and select Run 'test name'.

    You can also place the caret at the test class and press Ctrl+Shift+F10 .

    Running Cucumber tests with JUnit

    The results will be displayed on the Test Runner tab of the Run tool window. For more information, refer to Explore test results.

Run configurations for Cucumber

When you run your tests, IntelliJ IDEA creates a temporary run configuration with the default settings. You can use these temporary configurations as is, change their settings, and save them. For more information, refer to Run/debug configurations.

Create a new run configuration

  1. From the main menu, select Run | Edit Configurations.

  2. On the toolbar on the left, click Add New Configuration or press Alt+Insert and select Cucumber Java from the list.

    After that, you can complete the configuration using the options on the right. For the description of each option, refer to Run/Debug Configuration: Cucumber Java.

    Creating new run confugration for Cucumber
Last modified: 19 August 2020