Q3 of 21 · BDD / Cucumber
What is a feature file and what sections does it contain?
BDD / CucumberJuniorbddgherkinfeature-filestructure
Short answer
Short answer: A feature file is a plain-text file (extension .feature) written in Gherkin that describes one feature of the application. It contains a Feature description at the top and one or more Scenario (or Scenario Outline) blocks.
Detail
Feature: User account registration
As a new visitor
I want to create an account
So that I can access member-only content
Background:
Given the registration page is open
Scenario: Successful registration with valid data
When the user submits the form with valid details
Then a confirmation email is sent
And the user is logged in automatically
Scenario: Registration fails with duplicate email
Given a user account already exists with email "bob@example.com"
When the user tries to register with "bob@example.com"
Then an error message "Email already registered" is displayed
Scenario Outline: Registration fails for invalid email formats
When the user submits the form with email "<email>"
Then a validation error is shown
Examples:
| email |
| notanemail |
| @nodomain.com |
| user@ |
Sections:
- Feature — one per file. A short title plus optional description (often a user story). Describes the capability being specified.
- Background — steps that run before every scenario in the file. Keep it short — only include context genuinely shared by all scenarios.
- Scenario — a single concrete example with its own Given/When/Then.
- Scenario Outline + Examples — a parameterised template that runs once per row in the Examples table.
- Tags — @-prefixed labels placed above Feature or Scenario to filter execution.
One feature file per feature area keeps things manageable. Files that grow to 10+ scenarios usually need splitting.
// WHAT INTERVIEWERS LOOK FOR
All four sections (Feature, Background, Scenario, Scenario Outline/Examples). Knowing Background runs before every scenario in the file, not before the whole suite.