← スキル一覧に戻る

test-driven
by guvnr-dev
One config to govern them all. Universal AI coding assistant configuration for Claude, Cursor, Copilot, Windsurf, Aider, and 15+ tools.
⭐ 0🍴 0📅 2026年1月14日
SKILL.md
name: test-driven description: Implement test-driven development (TDD) practices. Write tests first, then implementation.
Test-Driven Development Skill
This skill guides test-driven development practices, ensuring code quality through comprehensive testing.
When to Use
Activate this skill when:
- Implementing new features
- Fixing bugs (write regression test first)
- Refactoring existing code
- The user requests TDD approach
TDD Workflow
┌─────────────────┐
│ 1. Write Test │ ← Start here
│ (Red) │
└────────┬────────┘
▼
┌─────────────────┐
│ 2. Write Code │
│ (Green) │
└────────┬────────┘
▼
┌─────────────────┐
│ 3. Refactor │
│ (Clean) │
└────────┬────────┘
│
└──────────────▶ Repeat
The Three Rules of TDD
- Write no production code except to pass a failing test
- Write only enough of a test to demonstrate a failure
- Write only enough production code to pass the test
Test Categories
| Type | Scope | Speed | When to Write |
|---|---|---|---|
| Unit | Single function/class | Fast | Every function |
| Integration | Component interactions | Medium | Every integration point |
| E2E | Full user workflows | Slow | Key user journeys |
| Regression | Known bug scenarios | Fast | Every bug fix |
Writing Good Tests
Test Structure (Arrange-Act-Assert)
test('should calculate total with tax', () => {
// Arrange - Set up test data
const cart = new Cart();
cart.addItem({ price: 100, quantity: 2 });
// Act - Execute the code under test
const total = cart.calculateTotal({ taxRate: 0.1 });
// Assert - Verify the result
expect(total).toBe(220);
});
Naming Conventions
// Pattern: should [expected behavior] when [condition]
test('should return empty array when no items match filter');
test('should throw error when user not authenticated');
test('should update cache when data changes');
What to Test
- Happy path: Normal expected usage
- Edge cases: Empty inputs, boundaries, limits
- Error conditions: Invalid inputs, failures
- State changes: Before and after operations
What NOT to Test
- Third-party library internals
- Language/framework features
- Trivial getters/setters
- Implementation details (test behavior)
Test Patterns
Testing Async Code
test('should fetch user data', async () => {
const user = await fetchUser(123);
expect(user.name).toBe('John');
});
Testing Errors
test('should throw on invalid input', () => {
expect(() => validate(null)).toThrow('Input required');
});
Using Mocks
test('should call API with correct params', () => {
const mockApi = jest.fn().mockResolvedValue({ data: [] });
await fetchData(mockApi, { page: 1 });
expect(mockApi).toHaveBeenCalledWith('/data?page=1');
});
Code Coverage Guidelines
| Metric | Target | Priority |
|---|---|---|
| Line coverage | 80%+ | High |
| Branch coverage | 75%+ | High |
| Function coverage | 90%+ | Medium |
| Critical paths | 100% | Critical |
Refactoring with Tests
When refactoring:
- Ensure existing tests pass
- Don't change tests and code simultaneously
- Make small, incremental changes
- Run tests after each change
- If tests break, you changed behavior (not just structure)
Commands
npm test # Run all tests
npm test -- --watch # Watch mode
npm test -- --coverage # Coverage report
npm test -- path/to/test.js # Single file
Troubleshooting
Tests Are Slow
- Mock external dependencies
- Use in-memory databases
- Parallelize test execution
- Focus unit tests, fewer E2E
Tests Are Flaky
- Avoid time-dependent assertions
- Use deterministic test data
- Properly await async operations
- Isolate test state
Hard to Test Code
- Refactor for testability
- Extract dependencies
- Use dependency injection
- Reduce coupling
スコア
総合スコア
75/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
✓説明文
100文字以上の説明がある
+10
○人気
GitHub Stars 100以上
0/15
✓最近の活動
1ヶ月以内に更新
+10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
レビュー
💬
レビュー機能は近日公開予定です



