Test Runner Architecture
TheCucumberRunner class serves as the entry point for test execution:
Key Annotations
@Suite
Marks this class as a JUnit Platform test suite, enabling it to aggregate and run multiple tests.
@IncludeEngines
Specifies the Cucumber engine for test execution:This integrates Cucumber’s Gherkin-based test execution with JUnit Platform, allowing feature files to be discovered and executed as JUnit tests.
@SelectClasspathResource
Defines where feature files are located:Points to
src/test/resources/features/ directory. All .feature files in this location and subdirectories are automatically discovered.Test Discovery
When you run./gradlew test, the following discovery process occurs:
JUnit Platform Initialization
Gradle’s test task uses
useJUnitPlatform() to activate the JUnit 5 test engine.Engine Activation
The
@IncludeEngines("cucumber") annotation loads the Cucumber test engine from the classpath:Feature File Scanning
Cucumber scans
src/test/resources/features/ for all .feature files based on @SelectClasspathResource("features").Test Execution Flow
Once tests are discovered, execution proceeds as follows:Scenario Lifecycle
- Before Hooks - Execute
@Beforeannotated methods - Step Execution - Run each step in the scenario sequentially
- After Hooks - Execute
@Afterannotated methods (even if steps fail) - Reporting - Serenity captures results, screenshots, and metadata
Screenplay Pattern Integration
Tests use the Screenplay pattern for actor-based test execution:- Uses an Actor to perform actions
- Executes Tasks, Interactions, or Questions
- Captures detailed execution data for Serenity reports
Test Output
During test execution, you’ll see real-time console output:testLogging configuration in build.gradle controls output verbosity:
Parallel Execution
Serenity Reporter Parallel
The runner usesSerenityReporterParallel plugin for thread-safe reporting:
Enabling Parallel Execution
To run scenarios in parallel, add JUnit configuration properties. Createsrc/test/resources/junit-platform.properties:
Parallel execution requires careful state management. Ensure:
- Each scenario is independent
- Actors don’t share mutable state
- Browser instances are isolated per thread
Parallel Execution Trade-offs
Benefits
Benefits
- Faster test execution
- Better CI/CD pipeline performance
- Increased test throughput
Considerations
Considerations
- Higher resource consumption (CPU, memory)
- More complex debugging
- Potential for timing-related issues
- Requires thread-safe test design
Tag-Based Execution
The@test tag in CucumberRunner filters scenarios:
@test tag run by default. Override via command line:
Tag Expressions
Cucumber supports boolean logic in tag filters:and- Both tags must be presentor- Either tag must be presentnot- Tag must not be present- Parentheses for grouping:
(@smoke or @regression) and not @wip
System Properties
The test task forwards all system properties:Continue on Failure
The build is configured to continue even when tests fail:- All scenarios execute regardless of individual failures
- Complete test coverage data is collected
- Full reports show all results
- CI pipelines get comprehensive feedback
Debugging Test Execution
View Detailed Logs
Run tests with verbose output:Check Test Discovery
Verify which tests are discovered:Inspect System Properties
Log all system properties during test execution by adding to a step definition:Test Execution Best Practices
Tag Organization
Tag Organization
Use a consistent tagging strategy:
@test- Scenarios ready for execution@smoke- Critical path tests@regression- Full regression suite@wip- Work in progress, exclude from CI@skip- Temporarily disabled tests
Scenario Independence
Scenario Independence
Each scenario should:
- Start from a clean state
- Not depend on other scenarios
- Clean up its own test data
- Be executable in any order
Meaningful Test Names
Meaningful Test Names
Write descriptive scenario names:
Step Reusability
Step Reusability
Design steps to be reusable across scenarios:
- Use parameterized steps
- Avoid hard-coded data in step definitions
- Leverage data tables and scenario outlines