AGENT SKILL
tdd
Enforces Test-Driven Development (Red-Green-Refactor). Use when writing unit tests, implementing TDD, or improving test coverage for any feature.
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
01 前言 Front Matter
- name
- tdd
- metadata
- { "labels": [ "tdd", "testing", "quality", "red-green-refactor" ], "triggers": { "files": [ "**/*.test.ts", "**/*.spec.ts", "**/*_test.go", "**/*Test.java", "**/*_test.dart", "**/*_spec.rb" ], "keywords": [ "tdd", "unit test", "write test", "red green refactor", "failing test", "test coverage" ] } }
- description
- Enforces Test-Driven Development (Red-Green-Refactor). Use when writing unit tests, implementing TDD, or improving test coverage for any feature.
02 资源文件 22
- 脚本core/color_palettes.py8.5 KB
- 脚本core/easing.py6.1 KB
- 脚本core/frame_composer.py14.1 KB
- 脚本core/gif_builder.py9.3 KB
- 脚本core/typography.py10.5 KB
- 脚本core/validators.py8.0 KB
- 脚本core/visual_effects.py14.5 KB
- 许可证LICENSE.txt11.1 KB
- 参考文档requirements.txt66 B
- 脚本templates/bounce.py3.0 KB
- 脚本templates/explode.py11.0 KB
- 脚本templates/fade.py9.9 KB
- 脚本templates/flip.py9.2 KB
- 脚本templates/kaleidoscope.py6.2 KB
- 脚本templates/morph.py11.0 KB
- 脚本templates/move.py9.2 KB
- 脚本templates/pulse.py8.4 KB
- 脚本templates/shake.py3.6 KB
- 脚本templates/slide.py9.1 KB
- 脚本templates/spin.py8.9 KB
- 脚本templates/wiggle.py9.8 KB
- 脚本templates/zoom.py9.9 KB
03 SKILL.md 正文
Test-Driven Development (TDD)
Priority: P1 (OPERATIONAL)
The Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST. Code written before the test must be deleted. Start over.
The TDD Cycle
- RED: Write a minimal failing test. Verify failure (Expected error, not typo).
- GREEN: Write simplest code to pass. Verify pass.
- REFACTOR: Clean up code while staying green.
AAA Structure (Mandatory)
Every test must follow Arrange-Act-Assert:
- Arrange: Set up inputs, stubs, mocks, and expected values.
- Act: Call the single unit under test.
- Assert: Verify output and side effects. One logical assertion per test. (See AAA Example for code structure).
Coverage Thresholds
- Minimum: 80% (Statements, Functions, Lines), 75% (Branches).
- Target: 90% (Statements, Functions, Lines), 85% (Branches).
- Configure in test runner config (e.g.
jest.config.ts,vitest.config.ts). Coverage below minimum is a build-gate failure.
Test Runner Commands
| Language | Runner | Watch Mode | Coverage |
|---|---|---|---|
| TypeScript/JS | jest / vitest |
vitest --watch |
vitest run --coverage |
| Go | go test |
go test -v ./... -count=1 |
go test -cover ./... |
| Java | JUnit 5 + Maven | mvn test |
mvn verify -P coverage |
| Kotlin | JUnit 5 + Kotest | ./gradlew test |
./gradlew jacocoTestReport |
| Dart/Flutter | flutter test |
flutter test --watch |
flutter test --coverage |
Core Principles
- Watch it Fail: Prove the test works.
- Minimalism: Don't add features/options beyond current test (YAGNI).
- Real Over Mock: Prefer real dependencies unless slow/flaky.
- One Reason to Fail: Test one behavior per test.
- Descriptive Names: e.g.
should_returnError_when_emailIsInvalid.
When to Use Mocks vs Real Dependencies
- Database: Real DB (test container) or in-memory; mock as last resort.
- HTTP/External APIs: Always mock.
- Filesystem: Use temp dir; mock for unit isolation.
- Time/Dates: Always mock/control.
- Internal services: Real if fast (<200ms); mock if cross-network.
Verification Checklist
- [ ] Every new function/method has a failing test first?
- [ ] Failure message was expected?
- [ ] Minimal code implemented passed?
- [ ] AAA structure followed?
- [ ] Coverage thresholds met?