| name | add-test |
| description | Add tests for a feature based on specs/issues. Trigger khi user noi "add test |
| allowed-tools | Bash(git *), Bash(find cat grep), Read, Write, Edit, Glob, Grep |
| priority | medium |
Add Test Skill
Overview
Generate tests for a feature dua tren spec issue trong specs/issues/. Skill nay se:
- Doc spec issue de hieu requirements va acceptance criteria
- Xac dinh tech stack va test framework phu hop
- Viet tests cover tat ca acceptance criteria + edge cases
- Khong thay doi source code, chi tao/cap nhat test files
Steps (thuc hien tuan tu)
-
Xac dinh issue can test
- Neu user dua issue number (#1, #45...) -> tim file:
specs/issues/{number}-*.md
- Neu khong co number -> lay tu branch hien tai:
git branch --show-current -> extract issue number tu branch name (pattern: feature/hung-#{number}-{slug})
- Doc toan bo file spec bang Read tool
-
Phan tich spec de xac dinh test cases
- Extract tu Acceptance Criteria -> moi criteria = 1 test case (it nhat)
- Extract tu Validation Rules -> moi rule = test cases cho valid + invalid inputs
- Extract tu Input/Output -> test expected output format
- Xac dinh edge cases: empty input, boundary values, special characters, error paths
-
Xac dinh test framework va structure
- Doc source code file (theo Implementation section trong spec) de hieu code structure
- Chon test framework phu hop voi tech stack:
- Ruby ->
minitest (stdlib) hoac rspec (neu da co trong project)
- JavaScript/TypeScript ->
jest hoac vitest
- Python ->
pytest
- Test file location:
test/ hoac spec/ folder (theo convention cua project)
- Naming:
test_{feature_name}.rb, {feature_name}_test.rb, hoac {feature_name}_spec.rb
-
Viet tests
- Tao test file voi cau truc ro rang:
- Group tests theo feature/behavior (describe/context blocks)
- Moi test co ten mo ta ro:
test "rejects email without @", it "masks password input"
- Cover:
- Happy path (valid inputs -> expected output)
- Validation errors (invalid email, short password, empty input)
- Edge cases (boundary values, special chars)
- Error handling (unexpected input types)
- Su dung assertions phu hop: assert_equal, assert_match, assert_raises...
- Mock/stub external dependencies neu can (vd: stdin for user input)
-
Verify va output
-
Ket thuc
- Hoi user: "Ban muon chay tests khong?" hoac "Can them test case nao khong?"
Luu y quan trong
- Luon doc spec TRUOC khi viet test -> khong gia dinh requirements
- Khong modify source code -> chi tao/edit test files
- Neu source code chua ton tai -> bao user va suggest implement truoc
- Uu tien stdlib test framework (minitest cho Ruby) truoc khi dung external gems