Running Cucumber from IDE

What Does Running from IDE Mean?

Running from an IDE means executing Cucumber tests directly from a development environment such as IntelliJ IDEA, Eclipse, or Visual Studio Code. Instead of opening a terminal and typing Maven or Gradle commands, a tester can run a runner class, feature file, or individual scenario from the IDE interface.

This is a common workflow while writing new scenarios, implementing step definitions, debugging failures, validating hooks, or checking a quick fix. The IDE starts JUnit, TestNG, or the JUnit Platform, and that test framework starts Cucumber execution.

Why Run Cucumber from an IDE?

IDE execution gives immediate feedback. A tester can write a feature file, run one scenario, see undefined step snippets, implement the Java method, place breakpoints, inspect variables, and rerun the scenario. This short feedback loop is much faster than waiting for a full CI pipeline.

Running from an IDE is especially useful during development. It supports debugging, navigation between steps and step definitions, local console output, quick reruns, and report generation. It is not a replacement for command-line or CI execution, but it is one of the most productive ways to build automation.

Execution Flow

Open Project
  -> Select Runner, Feature, or Scenario
  -> Click Run or Debug
  -> IDE Starts JUnit or TestNG
  -> Cucumber Engine Starts
  -> Feature Files Execute
  -> Results Display in IDE

The automation code is the same as command-line execution. The difference is how the run is launched and how the results are displayed. If the framework is configured correctly, IDE execution and Maven execution should produce consistent behavior.

Project Requirements

Before Cucumber can run from an IDE, the project must have feature files, step definitions, a runner class or JUnit Platform suite, required dependencies, a correct feature path, a correct glue path, and a valid build structure. Maven or Gradle dependencies should be refreshed after adding libraries.

src
  test
    java
      runners
      stepdefinitions
      hooks
    resources
      features

If the IDE cannot find feature files or step definitions, the problem is often project import, dependency resolution, feature path configuration, or glue package configuration.

Running a Runner Class

In JUnit 4 or TestNG projects, the simplest approach is to right-click the runner class and choose Run. The runner starts Cucumber and applies the configured feature path, glue path, tags, and plugins. This is useful for smoke runners, regression runners, API runners, and UI runners.

@CucumberOptions(
    features = "src/test/resources/features",
    glue = {"stepdefinitions", "hooks"},
    tags = "@Smoke"
)
public class SmokeRunner extends AbstractTestNGCucumberTests {
}

Running this class from the IDE executes only the scenarios selected by the runner configuration. If the runner has a tag filter, only matching scenarios run.

Running a Feature or Scenario

Many IDEs allow execution directly from a .feature file. A tester can right-click a feature file and run all scenarios in that file. Some IDEs also allow running a single scenario by placing the cursor inside the scenario and choosing Run Scenario.

This is useful while developing automation because it avoids running the full suite. A tester can focus on one scenario, fix step definitions, validate assertions, and then expand execution to the full feature or runner.

Debugging with Breakpoints

The biggest advantage of IDE execution is debugging. You can place a breakpoint inside a step definition, hook, page object, API client, utility method, or assertion. When execution reaches that line, the IDE pauses and lets you inspect variables, WebDriver state, API responses, scenario context, and the call stack.

@When("the user logs in")
public void userLogsIn() {
    // Add breakpoint here
    loginPage.login(username, password);
}

Debugging is invaluable for Selenium failures, data issues, timing problems, null values, incorrect locators, and API response mismatches. Instead of guessing from logs alone, the tester can inspect the runtime state directly.

Step Navigation and Undefined Steps

Modern IDEs with Cucumber support can navigate from a Gherkin step to its Java step definition. This improves productivity because testers can quickly understand which code implements a step. IDEs may also highlight undefined steps and provide step definition skeleton suggestions.

Dry run mode can also help validate step mappings without executing automation code. This is useful when a feature file is new and the team wants to identify missing step definitions before running a browser or API flow.

Reports from IDE Runs

If report plugins are configured, IDE execution can generate the same reports as command-line execution. For example, an HTML plugin writes a report under target even when execution starts from IntelliJ or Eclipse.

plugin = {
    "pretty",
    "html:target/report.html",
    "json:target/report.json"
}

This is useful because local development runs can still produce reviewable artifacts. However, CI reports remain the official evidence for team builds and releases.

IDE vs Command Line

IDE ExecutionCommand-Line Execution
Best for local development and debuggingBest for automation and CI/CD
Supports breakpointsScriptable and repeatable
Easy to run one scenarioEasy to run scheduled suites
InteractiveNon-interactive

Both execution modes should use the same framework configuration. If tests pass in the IDE but fail from Maven, compare working directory, classpath, dependencies, properties, feature paths, and report paths.

Common Problems

Common IDE execution issues include missing dependencies, wrong runner configuration, feature files not found, undefined steps, plugins not generating reports, and the IDE using an outdated project model. Refresh Maven or Gradle, confirm runner configuration, verify glue packages, and check that feature files are under test resources.

If a feature runs from the IDE but not from CI, do not assume CI is wrong. IDEs can hide classpath and working-directory differences. The command-line run is usually the more reliable measure of framework portability.

Best Practices

Use IDE execution for fast development, debugging, and scenario-level validation. Run individual scenarios while implementing automation. Use runner classes for organized suite execution. Use breakpoints to diagnose complex failures. Refresh dependencies after adding libraries. Generate local reports when debugging evidence is useful.

Before committing, run at least the relevant Maven or Gradle command to confirm the tests work outside the IDE. CI/CD does not run by right-clicking feature files, so command-line compatibility matters.

Real-Time Development Workflow

A common workflow begins with a tester or developer writing a new Gherkin scenario. The scenario is reviewed for business readability. The tester runs the scenario from the IDE and sees undefined step suggestions. Then the tester implements step definitions, connects them to page objects or API clients, and runs the scenario again. If the scenario fails, the tester uses Debug mode and breakpoints to inspect the runtime state.

After the single scenario passes, the tester runs the full feature file. This catches interaction problems between scenarios, background setup, hooks, and test data. After the feature file passes, the tester runs the runner class or relevant tag suite. Finally, before committing, the tester runs the command-line Maven or Gradle command to confirm that the framework works outside the IDE.

This flow gives fast feedback without losing discipline. The IDE is used for development speed. Command-line execution is used for portability. CI/CD is used for team-level confidence.

Running with Different IDEs

IntelliJ IDEA usually provides strong support for Cucumber JVM, Java navigation, Maven and Gradle import, breakpoints, and run configurations. Eclipse can also run Cucumber through JUnit or TestNG runner classes, especially when the project dependencies are correctly imported. Visual Studio Code can support Cucumber and Java workflows with the right extensions, but setup may require more attention.

The exact button names and shortcuts differ by IDE, but the concept is the same. The IDE starts the Java test framework, and the Java test framework starts Cucumber. If the runner configuration is correct, the same feature files and step definitions execute regardless of IDE.

IDE Run Configurations

Most IDEs allow saved run configurations. A run configuration can specify the runner class, working directory, VM options, environment variables, system properties, and test framework. This is useful when the framework needs values such as -Denv=qa, -Dbrowser=chrome, or -Dcucumber.filter.tags=@Smoke.

Saved configurations help teams avoid repeated manual setup. However, important configuration should still be documented in the project README or framework guide. If only one developer's IDE knows how to run the suite, the framework is not truly maintainable.

Troubleshooting IDE-Only Failures

If a test passes from Maven but fails in the IDE, check the IDE working directory, module classpath, dependency import, JDK version, and run configuration properties. If a test passes in the IDE but fails from Maven, check whether the IDE is using different VM options, environment variables, or resource paths. Consistency matters.

When debugging difficult IDE issues, close the IDE, clean the project, refresh Maven or Gradle, and rerun the command-line build. Then reopen the IDE and reimport the project. Many IDE problems come from stale project metadata rather than Cucumber itself.

Interview-Ready Summary

Running from an IDE allows Cucumber tests to execute directly from IntelliJ IDEA, Eclipse, or Visual Studio Code. Tests can be run at runner, feature, or scenario level. IDE execution supports debugging, breakpoints, step navigation, quick reruns, and local report generation.

The golden rule is to use the IDE for fast feedback and debugging, but keep the framework compatible with Maven, Gradle, and CI/CD execution.