← Back to list

tdd
by sharpner
⭐ 1🍴 0📅 Jan 9, 2026
SKILL.md
name: tdd description: Use when implementing ANY new feature or fixing bugs. Test-Driven Development - write tests BEFORE implementation code.
Test-Driven Development (TDD)
Core Rule: Write tests BEFORE implementation code.
"If you didn't watch the test fail, you don't know if it tests the right thing."
The Red-Green-Refactor Cycle
1. RED: Write Failing Test First
// Write this FIRST
it('should validate email format', () => {
const result = validateEmail('invalid');
expect(result.valid).toBe(false);
expect(result.error).toBe('Invalid email format');
});
Run test → MUST FAIL (for the right reason: missing feature, not typo)
2. GREEN: Implement Minimum Code
// Write this SECOND - simplest code to pass
function validateEmail(email: string) {
if (!email.includes('@')) {
return { valid: false, error: 'Invalid email format' };
}
return { valid: true };
}
Run test → MUST PASS
3. REFACTOR: Clean Up
Improve code quality while keeping tests green.
Mandatory Verification Points
| Point | What to Check |
|---|---|
| After writing test | Test fails for correct reason (missing feature) |
| After implementing | Test passes, no other tests break |
Non-Negotiable Rules
- ❌ Delete any production code written before tests
- ❌ Never keep pre-written code "as reference"
- ❌ No exceptions - TDD applies to ALL features and bug fixes
- ❌ No unnecessary mocking - tests use real code paths
For Bug Fixes (Critical!)
- Write test that reproduces the bug (must fail)
- Verify test fails for the bug reason
- Implement fix
- Verify test passes
- Verify no regression in other tests
// Bug: User with spaces in name causes crash
it('should handle names with spaces', () => {
// This MUST fail before fix
expect(() => createUser('John Doe')).not.toThrow();
});
Rationalizations to REJECT
| Excuse | Reality |
|---|---|
| "Manual testing is enough" | Manual testing doesn't catch regressions |
| "TDD slows me down" | Debugging untested code takes 10x longer |
| "This is too simple" | Simple code still needs regression protection |
| "I'll add tests later" | You won't. And you'll introduce bugs. |
Output Format
When implementing:
**TDD Cycle:**
1. ✅ Test written: `validateEmail returns error for invalid format`
2. ✅ Test fails: "validateEmail is not defined" (correct reason)
3. ✅ Implementation: Added validateEmail function
4. ✅ Test passes: 1/1 assertions passed
5. ✅ No regressions: All 47 tests still pass
Score
Total Score
50/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon