| name | bdd-test |
| description | Create Go tests from BDD feature specifications. |
Description
Generate Go test files from Gherkin feature specifications stored in features/*.spec.
Each test class is named after the feature and contains nested test functions
representing rules and scenarios.
Scope
- User-provided scope takes priority (e.g., specific spec file)
- If none provided: create missing tests and update existing ones based on all specs in
features/*.spec
General rules
- Ask if anything is unclear - do not guess
- All phases are mandatory - do not skip without user approval
- Track non-trivial steps with tasks
Skill-specific rules
- Name test files as
features/<feature_name>_test.go
- Cover all scenarios from the spec, even if they already have tests
- Use exact text from spec for descriptions
- Use
t.Run to nest background, rules, and scenarios
- Write unit tests: Call functions directly, do not run the program or its binary.
- Adhere to the conventions provided by the examples
- If there is a discrepancy between the spec and existing tests, ask for clarification
Phase 1: Preparation
- Read the spec file: Understand feature, rules, and scenarios
- Read relevant source code: Understand the function being tested
Phase 2: Execution
-
Create test class:
func TestFeature<FeatureName>(t *testing.T) { ... }
-
Add feature comment directly before test class (no blank line):
func TestFeature<FeatureName>(t *testing.T) {
-
Add background comment directly at the beginning of the test class:
func TestFeature<FeatureName>(t *testing.T) {
-
Add rules and scenarios as nested t.Run:
t.Run("Rule: <rule name>", func(t *testing.T) {
t.Run("Scenario: <scenario name>", func(t *testing.T) {
})
})
Add the comments before the implementation or concrete assertion.
-
Implement steps (use comments matching the step text):
Given/And → setup fixtures, mock responses
When → call the function under test
Then/And/But → assertions
Phase 3: Verification
- Build: Run
go build . to confirm no compilation errors
- Run: Run
go test ./... to confirm tests pass
- Coverage: Ensure all scenarios from spec are covered
Example
Feature file (features/calculator.spec):
Feature: Calculator
Simple arithmetic operations
Background:
Given a calculator instance
Rule: Addition
Scenario: Adding two positive numbers
Given the numbers 2 and 3
And the operation is addition
When adding
Then the result is 5
But the display shows "5"
Generated test (features/calculator_test.go):
package main
func TestFeatureCalculator(t *testing.T) {
t.Run("Rule: Addition", func(t *testing.T) {
t.Run("Scenario: Adding two positive numbers", func(t *testing.T) {
calc := NewCalculator()
a, b := 2, 3
op := "addition"
result := calc.Add(a, b)
if result != 5 {
t.Errorf("expected 5, got %d", result)
}
display := calc.Display()
if display != "5" {
t.Errorf("expected display \"5\", got %q", display)
}
})
})
}