Answer
Code in TestRunner Class
Answer: No Code Inside the Class Body
The TestRunner class should be empty — no methods, no logic, no assertions inside its class body. It should only include:
- ✓Package declaration
- ✓Import statements
- ✓
@CucumberOptionsannotation - ✓Class declaration (extending
AbstractTestNGCucumberTestsfor TestNG)
Correct TestRunner (Empty Body)
Java
package runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
// All configuration is in the annotation — no code in the body
@CucumberOptions(
features = "src/test/resources/features",
glue = {"stepDefinitions", "hooks"}
)
public class TestRunner extends AbstractTestNGCucumberTests {
// NOTHING HERE — this is intentional and correct
}
Exception: Parallel Execution DataProvider
The only acceptable code is overriding scenarios() for parallel execution:
Java
@CucumberOptions(...)
public class TestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true) // ← only allowed code
public Object[][] scenarios() {
return super.scenarios();
}
}
Where Should Code Go?
| Code Type | Where It Lives |
|---|---|
| Browser setup / teardown | @Before / @After in Hooks.java |
| Step actions (click, type) | Step Definition classes |
| Page interactions | Page Object classes |
| Test data | Properties files / Excel / DataProvider |
| Assertions | Step definition @Then methods |
| Driver management | BaseTest / DriverFactory class |
Why Keep TestRunner Empty?
- ✓Separation of Concerns — TestRunner configures, step definitions act
- ✓Readability — Configuration in one place, logic in another
- ✓Cucumber convention — Framework is designed for empty runner
- ✓Maintainability — Changing test behavior = change step defs, not runner
