Test-Driven Development (TDD)
Enforce the RED-GREEN-REFACTOR cycle for all code changes.
terminal Use this skill with: /ak_sk_test-driven-development
When to Use
Use this skill when:
- Implementing new features
- Fixing bugs
- Adding new functionality
Workflow
Step 1: RED - Write Failing Test
- Understand the requirement clearly
- Write a test that describes the expected behavior
- Run the test - confirm it FAILS
- If test passes without code, the test is wrong
Checklist:
- Test describes expected behavior
- Test is minimal and focused
- Test fails for the right reason
Step 2: GREEN - Make It Pass
- Write the MINIMUM code to pass the test
- Don't add extra functionality
- Don't optimize yet
- Run the test - confirm it PASSES
Checklist:
- Only code needed to pass is written
- Test now passes
- No other tests broken
Step 3: REFACTOR - Clean Up
- Remove duplication
- Improve naming
- Simplify logic
- Run tests after each change
Checklist:
- Code is clean and readable
- No duplication
- All tests still pass
Anti-Patterns to Avoid
- rocket_launch Writing code before tests
- rocket_launch Writing multiple tests before implementing
- rocket_launch Over-engineering first implementation
- rocket_launch Skipping the refactor step
- rocket_launch Testing implementation details instead of behavior
Verification
Before marking complete:
npm run test # All tests pass
npm run typecheck # No type errors
npm run lint # No lint errors
Example
// RED: Write failing test
test('should authenticate user', () => {
expect(authenticate('user', 'pass')).toBe(true);
});
// GREEN: Write minimum code
function authenticate(username: string, password: string): boolean {
return username === 'user' && password === 'pass';
}
// REFACTOR: Clean up
function authenticate(username: string, password: string): boolean {
return validateCredentials(username, password);
}
Related Skills
- Unit Testing - Test individual functions
- Integration Testing - Test component interactions
- Refactoring - Improve code structure