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: marks new tests; marks successful tests; icon marks failed tests.
Run a scenario
Click 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.
Run a feature
Click 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.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.
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.
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.
In the Project tool window, right-click the package with step definitions and select .
Name the new class (for example,
RunCucumberTest
) and press Enter.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).Click in the gutter and select Run 'test name'.
You can also place the caret at the test class and press Ctrl+Shift+F10.
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
In the main menu, go to
.On the toolbar on the left, click 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.