|
| 1 | +--- |
| 2 | +description: Generate a reviewer-friendly test plan documenting what behaviors will be verified for the feature. |
| 3 | +handoffs: |
| 4 | + - label: Generate Tasks |
| 5 | + agent: speckit.tasks |
| 6 | + prompt: Generate implementation tasks including test tasks |
| 7 | + send: true |
| 8 | + - label: Analyze Consistency |
| 9 | + agent: speckit.analyze |
| 10 | + prompt: Check consistency across spec, plan, and tests |
| 11 | + send: true |
| 12 | +--- |
| 13 | + |
| 14 | +## User Input |
| 15 | + |
| 16 | +```text |
| 17 | +$ARGUMENTS |
| 18 | +``` |
| 19 | + |
| 20 | +You **MUST** consider the user input before proceeding (if not empty). |
| 21 | + |
| 22 | +## Purpose |
| 23 | + |
| 24 | +Generate a `tests.md` file that: |
| 25 | +1. Documents what behaviors will be tested (for domain reviewers) |
| 26 | +2. Provides implementation guidance (for developers/AI) |
| 27 | +3. Ensures traceability from requirements to tests |
| 28 | + |
| 29 | +The primary audience is **non-technical reviewers** who want to verify that |
| 30 | +important requirements have test coverage. Technical details go in an appendix. |
| 31 | + |
| 32 | +## Outline |
| 33 | + |
| 34 | +1. **Setup**: Run `.specify/scripts/bash/check-prerequisites.sh --json` from repo root |
| 35 | + and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute. |
| 36 | + |
| 37 | +2. **Load source documents**: Read from FEATURE_DIR: |
| 38 | + - **Required**: spec.md (user stories, acceptance scenarios, edge cases) |
| 39 | + - **Required**: plan.md (project structure, test file locations) |
| 40 | + - If spec.md doesn't exist, ERROR with message to run `/speckit.specify` first |
| 41 | + - If plan.md doesn't exist, ERROR with message to run `/speckit.plan` first |
| 42 | + |
| 43 | +3. **Check for existing test artifacts**: |
| 44 | + - Check if tasks.md exists in FEATURE_DIR |
| 45 | + - Check if test files exist in locations specified by plan.md (e.g., `tests/unit/`) |
| 46 | + - Note what was found (will be used in step 7) |
| 47 | + |
| 48 | +4. **Extract test requirements from spec.md**: |
| 49 | + - User stories with priorities (P1, P2, P3...) |
| 50 | + - Acceptance scenarios (Given/When/Then) |
| 51 | + - Edge cases section |
| 52 | + - Functional requirements (FR-001, FR-002...) |
| 53 | + - Success criteria |
| 54 | + |
| 55 | +5. **Extract from plan.md**: |
| 56 | + - Project structure (test directory layout) |
| 57 | + - Testing framework |
| 58 | + - Technical context |
| 59 | + |
| 60 | +6. **Generate tests.md** using `.specify/templates/tests-template.md`: |
| 61 | + - Fill feature name and branch from spec.md |
| 62 | + - Generate Test Summary with key behaviors (plain language) |
| 63 | + - Generate Behavior Coverage section for each user story |
| 64 | + - Map acceptance scenarios to test descriptions |
| 65 | + - Generate Edge Cases table from spec.md edge cases |
| 66 | + - Fill Coverage Checklist |
| 67 | + - Fill Implementation Notes with file paths and structure from plan.md |
| 68 | + |
| 69 | +7. **Reconciliation** (if existing artifacts were found in step 3): |
| 70 | + - Compare generated tests.md against existing tasks.md and/or test files |
| 71 | + - Report discrepancies in a clear summary: |
| 72 | + - **Covered**: Spec requirements that have existing test coverage |
| 73 | + - **Gaps**: Spec requirements that lack test coverage |
| 74 | + - **Orphans**: Existing tests that don't map to spec requirements |
| 75 | + - For each gap, ask user: "Add to tasks?" or "Note as out-of-scope?" |
| 76 | + - For each orphan, ask user: "Missing from spec?" or "Remove test?" |
| 77 | + - Update tests.md to reflect decisions (mark covered items, note gaps) |
| 78 | + |
| 79 | +8. **Report**: Output path to generated tests.md and summary: |
| 80 | + - Count of user stories covered |
| 81 | + - Count of edge cases covered |
| 82 | + - Count of acceptance scenarios mapped |
| 83 | + - Flag any gaps (user stories without tests, unmapped scenarios) |
| 84 | + |
| 85 | +## Generation Rules |
| 86 | + |
| 87 | +### Language Guidelines |
| 88 | + |
| 89 | +**Primary sections (for reviewers)** - Use plain, non-technical language: |
| 90 | +- "Load a configuration file and verify all values are accessible" |
| 91 | +- "Attempt to save with missing required fields, confirm error message" |
| 92 | +- NOT: "Assert model.field == expected using pytest fixture" |
| 93 | +- NOT: "Mock the database connection and verify query parameters" |
| 94 | + |
| 95 | +**Implementation Notes (for developers)** - Technical details allowed: |
| 96 | +- File paths, test names, fixture locations |
| 97 | +- Framework-specific patterns |
| 98 | +- Directory structure |
| 99 | + |
| 100 | +### Mapping Acceptance Scenarios |
| 101 | + |
| 102 | +For each acceptance scenario in spec.md: |
| 103 | + |
| 104 | +``` |
| 105 | +Given [initial state], When [action], Then [expected outcome] |
| 106 | +``` |
| 107 | + |
| 108 | +Create a test description: |
| 109 | + |
| 110 | +``` |
| 111 | +| Requirement | How It's Tested | |
| 112 | +|-------------|-----------------| |
| 113 | +| [Action] produces [outcome] | [Plain description of test] | |
| 114 | +``` |
| 115 | + |
| 116 | +### Edge Case Coverage |
| 117 | + |
| 118 | +For each edge case in spec.md, create a row: |
| 119 | + |
| 120 | +``` |
| 121 | +| Scenario | Expected Behavior | Covered | |
| 122 | +|----------|-------------------|---------| |
| 123 | +| [Edge case from spec] | [Expected handling] | [ ] | |
| 124 | +``` |
| 125 | + |
| 126 | +### Handling Missing Information |
| 127 | + |
| 128 | +- If spec.md has no edge cases section: Add placeholder row with TODO |
| 129 | +- If acceptance scenarios are vague: Flag in Open Questions section |
| 130 | +- If plan.md lacks test directory structure: Ask user to clarify before proceeding |
| 131 | + |
| 132 | +### Coverage Checklist |
| 133 | + |
| 134 | +Always include these standard checks: |
| 135 | +- [ ] Every user story has test coverage defined |
| 136 | +- [ ] All acceptance scenarios from spec.md are addressed |
| 137 | +- [ ] Edge cases from spec.md are covered |
| 138 | +- [ ] Invalid inputs produce clear error messages |
| 139 | +- [ ] Each test maps back to a requirement |
| 140 | + |
| 141 | +## Output Location |
| 142 | + |
| 143 | +Write to: `FEATURE_DIR/tests.md` |
0 commit comments