SpecFlow Support
Behavior-Driven Development (BDD) testing with SpecFlow and Gherkin.
Overview
C# Dev Tools provides syntax highlighting and support for SpecFlow feature files.
Gherkin Syntax Highlighting
Feature files (.feature
) have full syntax highlighting for:
- Feature: Feature definitions
- Scenario: Test scenarios
- Given/When/Then: BDD steps
- And/But: Additional steps
- Examples: Scenario outlines
- Tags: Feature and scenario tags
Running SpecFlow Tests
SpecFlow tests integrate with the Test Explorer:
- Test Explorer automatically discovers SpecFlow scenarios
- Run scenarios like regular unit tests
- Debug scenarios with breakpoints in step definitions
- View results in Test Explorer
Creating Feature Files
Create .feature
files using:
- Quick Add (
Shift+F2
): EnterMyFeature.feature
- Right-click in Solution Explorer: Add > New File
- Manually create with
.feature
extension
Step Definitions
Create step definitions in C# files:
[Binding]
public class UserSteps
{
[Given(@"a user named (.*)")]
public void GivenAUserNamed(string name)
{
// Step implementation
}
}
Best Practices
- Keep feature files focused and readable
- Use descriptive scenario names
- Organize step definitions logically
- Tag scenarios for filtering
- Use scenario outlines for data-driven tests
Integration
- Feature files show in Solution Explorer
- Scenarios appear in Test Explorer
- Full debugging support
- Test results show in output panel