Answer
Maximum Scenarios in a Feature File
Technical Limit
Cucumber has no enforced hard limit on the number of scenarios in a feature file. You can technically add hundreds of scenarios to a single file.
Recommended Best Practice
Keep feature files to a maximum of 10 scenarios. However, this number can vary from project to project and organization to organization.
Why Limit Scenarios Per Feature File?
CODE
1. READABILITY
- Files become hard to scan with 30+ scenarios
- Difficult to find specific scenarios quickly
2. MAINTAINABILITY
- One change in Background affects all scenarios
- Large files have higher merge conflict risk
3. FOCUS
- Each feature file should test ONE feature/module
- Mixing multiple features in one file violates SRP
4. EXECUTION TIME
- Smaller files = faster parallel execution by feature
- Easier to tag and run subsets
File Organization Strategy
CODE
features/
login/
login_valid.feature (5 scenarios)
login_invalid.feature (6 scenarios)
login_security.feature (4 scenarios)
cart/
add_to_cart.feature (8 scenarios)
remove_from_cart.feature (5 scenarios)
checkout/
payment.feature (10 scenarios)
shipping.feature (7 scenarios)
Signs You Need to Split a Feature File
- ✓More than 10 scenarios
- ✓Background has more than 3-4 steps
- ✓Scenarios test unrelated functionality
- ✓File is longer than 100 lines
- ✓Team members frequently get merge conflicts in the same file
