</>

Technology

Cucumber

Difficulty

Beginner

Interview Question

What is the starting point of execution for Cucumber feature files?

Answer

Starting Point of Execution in Cucumber

Answer: The TestRunner Class

When Cucumber is integrated with Selenium (and TestNG/JUnit), the TestRunner class is the starting point of execution. You run this class (or specify it in testng.xml) to trigger all Cucumber tests.

Execution Flow from TestRunner

CODE
1. JVM starts TestRunner class
          ↓
2. @CucumberOptions is read:
   - features → where .feature files are
   - glue → where step definitions are
   - plugin → report format and path
   - tags → which scenarios to run
          ↓
3. Cucumber scans feature files in the features path
          ↓
4. For each Scenario:
   - Matches each step to a @Given/@When/@Then method
   - Executes @Before hooks
   - Executes step methods in order
   - Executes @After hooks
          ↓
5. Reports generated via plugin configuration

Ways to Trigger Execution

MethodHow
IDERight-click TestRunner → Run As → TestNG Test
Mavenmvn test (if TestRunner is configured in pom.xml)
testng.xmlmvn test -DsuiteXmlFile=testng.xml
Command linejava -cp ... io.cucumber.core.cli.Main --features ...
JenkinsMaven build step with mvn test
Feature fileRight-click .feature file → Run As → Cucumber Feature

Setting Up Maven Surefire for TestRunner

XML
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.2.5</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

Note on Feature File Direct Execution

You can right-click a .feature file and run it directly in IDE — but in CI/CD pipelines, the TestRunner class is always the starting point.

Follow AutomateQA

Related Topics