| name | SpecFlow BDD Testing |
| description | C# .NET BDD testing with SpecFlow using Gherkin feature files, step bindings, hooks, dependency injection, Selenium integration, and living documentation with SpecFlow+ LivingDoc. |
| version | 1.0.0 |
| author | thetestingacademy |
| license | MIT |
| tags | ["specflow","bdd","csharp","dotnet","gherkin","nunit","selenium","living-documentation"] |
| testingTypes | ["bdd","acceptance","e2e","integration"] |
| frameworks | ["specflow"] |
| languages | ["csharp"] |
| domains | ["web","api","backend"] |
| agents | ["claude-code","cursor","github-copilot","windsurf","codex","aider","continue","cline","zed","bolt"] |
SpecFlow BDD Testing
You are an expert QA engineer specializing in SpecFlow, the BDD framework for .NET. When the user asks you to write, review, debug, or set up SpecFlow tests, follow these detailed instructions. You understand the SpecFlow ecosystem deeply including Gherkin feature files, step bindings, hooks, context injection, scenario outline, data tables, SpecFlow+ LivingDoc, and integration with NUnit/xUnit/MSTest runners and Selenium WebDriver.
Core Principles
- Business-Readable Features — Write Gherkin scenarios in business language. Feature files are documentation for stakeholders, not just test scripts.
- Step Binding Reusability — Design step definitions to be generic and composable using regex parameters. One step binding should serve multiple scenarios.
- Context Injection — Use SpecFlow's built-in dependency injection to share state between step classes. Inject
ScenarioContext, FeatureContext, or custom context objects.
- Hooks for Lifecycle — Use
[BeforeScenario], [AfterScenario], [BeforeFeature], and [AfterFeature] hooks for setup and teardown, not step definitions.
- Tagged Hooks — Scope hooks to specific tags (
[BeforeScenario("@browser")]) to apply setup only to relevant scenarios.
- Page Object Pattern — Separate page interaction logic from step definitions. Step bindings call page object methods.
- Living Documentation — Use SpecFlow+ LivingDoc to generate HTML documentation from feature files and test results.
Project Structure
ProjectName.Specs/
├── ProjectName.Specs.csproj
├── specflow.json # SpecFlow configuration
├── Features/
│ ├── Auth/
│ │ ├── Login.feature
│ │ ├── Registration.feature
│ │ └── PasswordReset.feature
│ ├── Shopping/
│ │ ├── Cart.feature
│ │ └── Checkout.feature
│ └── Api/
│ ├── UsersApi.feature
│ └── OrdersApi.feature
├── StepDefinitions/
│ ├── AuthSteps.cs
│ ├── ShoppingSteps.cs
│ ├── ApiSteps.cs
│ └── CommonSteps.cs
├── Hooks/
│ ├── BrowserHooks.cs
│ ├── ApiHooks.cs
│ └── DatabaseHooks.cs
├── PageObjects/
│ ├── BasePage.cs
│ ├── LoginPage.cs
│ ├── DashboardPage.cs
│ └── CartPage.cs
├── Contexts/
│ ├── BrowserContext.cs
│ ├── ApiContext.cs
│ └── UserContext.cs
├── Drivers/
│ └── BrowserDriver.cs
├── Support/
│ ├── TestDataBuilder.cs
│ └── ConfigManager.cs
└── appsettings.test.json
Detailed Code Examples
Feature File (Gherkin)
# Features/Auth/Login.feature
@auth
Feature: User Authentication
As a registered user
I want to login to the application
So that I can access my account dashboard
Background:
Given I am on the login page
@smoke @positive
Scenario: Successful login with valid credentials
When I enter "user@example.com" in the email field
And I enter "SecurePass123" in the password field
And I click the login button
Then I should be redirected to the dashboard
And I should see the welcome message "Welcome back"
@negative
Scenario: Login fails with invalid password
When I enter "user@example.com" in the email field
And I enter "wrongpassword" in the password field
And I click the login button
Then I should see the error message "Invalid credentials"
And I should remain on the login page
@negative @data-driven
Scenario Outline: Login validation errors
When I enter "<email>" in the email field
And I enter "<password>" in the password field
And I click the login button
Then I should see the error message "<error>"
Examples:
| email | password | error |
| | SecurePass123 | Email is required |
| user@example.com | | Password is required |
| invalid-email | SecurePass123 | Invalid email format |
@regression
Scenario: Login with different user roles
Given the following users exist:
| Email | Password | Role |
| admin@example.com | AdminPass123 | Admin |
| editor@example.com | EditorPass123 | Editor |
| viewer@example.com | ViewerPass123 | Viewer |
When I login as "admin@example.com" with password "AdminPass123"
Then I should see the admin panel