test-driven-development
Apply TDD methodology with Red-Green-Refactor cycle. Use when implementing features, fixing bugs, or when user says "TDD", "test first", "test-driven". Ensures code quality through disciplined test-first development.
What this skill does
# Test-Driven Development (TDD)
## Core Principle
**Write tests before code. Always.** TDD is not about testing—it's about design through small, disciplined steps.
## When to Use This Skill
- User explicitly requests TDD ("use TDD", "test first", "test-driven")
- Implementing new features
- Fixing bugs (write failing test that reproduces bug first)
- Refactoring existing code (ensure tests exist first)
## The Three Laws (Never Violate)
1. Write **NO production code** without a failing test first
2. Write **only enough test** to demonstrate one failure
3. Write **only enough code** to pass that test
## Protocol
### Phase 1: RED - Write Failing Test
```
□ Write ONE test that defines desired behavior
□ Run test - verify it FAILS
□ Verify it fails for the RIGHT reason (not syntax error)
□ DO NOT write implementation yet
Evidence required: Show test output with failure message
```
### Phase 2: GREEN - Minimal Implementation
```
□ Write MINIMAL code to make test pass
□ Resist urge to add extra features
□ Run test - verify it PASSES
□ If test still fails, fix implementation (not test)
Evidence required: Show test output with pass
```
### Phase 3: REFACTOR - Clean Code
```
□ Remove code duplication (DRY)
□ Improve naming for clarity
□ Extract complex logic into functions
□ Run ALL tests - must stay green throughout
□ Check test coverage on changed lines
Evidence required: Show all tests still passing after refactor
```
### Cycle Complete → Repeat
After REFACTOR, start new RED phase for next behavior.
## Common Mistakes to Avoid
### Writing Multiple Tests at Once
```
❌ WRONG: Test entire feature in one go
✅ CORRECT: One test at a time. Pass it. Refactor. Next test.
```
### Skipping Refactor Phase
```
❌ WRONG: "Tests pass, ship it!"
✅ CORRECT: ALWAYS refactor. Clean code is the goal.
```
### Implementation Before Test
```
❌ WRONG: Write code, then add tests after
✅ CORRECT: If code exists before test, delete it and start with test
```
### Over-Engineering in GREEN
```
❌ WRONG: Add error handling, edge cases, optimizations
✅ CORRECT: Simplest thing that makes THIS test pass
```
## Workflow Example
```
Task: "Add user login feature"
RED Phase:
1. Write test: test_login_with_valid_credentials()
2. Run: pytest -v → FAILED (no login function exists)
3. Evidence: "FAILED - AttributeError: 'User' has no 'login'"
GREEN Phase:
4. Write minimal login() method
5. Run: pytest -v → PASSED
6. Evidence: "1 passed in 0.03s"
REFACTOR Phase:
7. Extract password hashing to separate function
8. Improve variable names
9. Run: pytest -v → PASSED (still)
10. Evidence: "1 passed in 0.02s"
Next cycle: test_login_with_invalid_credentials()
```
## Test Patterns
### Arrange-Act-Assert (AAA)
```python
def test_user_can_login():
# Arrange
user = User(email="[email protected]", password="secret")
# Act
result = user.login("secret")
# Assert
assert result.success is True
assert result.token is not None
```
### Given-When-Then (BDD style)
```python
def test_login_with_wrong_password():
# Given a registered user
user = create_user(password="correct")
# When they attempt login with wrong password
result = user.login("wrong")
# Then login should fail
assert result.success is False
assert "Invalid password" in result.error
```
## Anti-Patterns
```
❌ Write test that passes immediately (test proves nothing)
❌ Test implementation details instead of behavior
❌ Skip tests for "simple" code
❌ Write tests after implementation "because we're in a hurry"
❌ Large tests that verify many things at once
✅ Each test verifies ONE behavior
✅ Test names describe the behavior being tested
✅ Tests are independent (no shared state)
✅ Tests run fast (mock external dependencies)
```
## Integration with Other Skills
- **pre-task-checkpoint**: Run checkpoint before each RED phase to frame what behavior to test
- **evidence-reasoning**: Show actual test output, never claim "tests pass" without evidence
- **completion-discipline**: Each GREEN phase requires evidence of passing test
- **verification-calibration**: Match test rigor to feature stakes (🔴 critical features need comprehensive tests)
- **clarifying-questions**: Clarify expected behavior BEFORE writing test
## Self-Check
```
Before moving from RED to GREEN:
[ ] Test actually fails?
[ ] Fails for the right reason?
[ ] Test name describes behavior?
Before moving from GREEN to REFACTOR:
[ ] Test passes?
[ ] Implementation is minimal?
[ ] No premature optimization?
Before starting next cycle:
[ ] Code is clean?
[ ] All tests still pass?
[ ] Ready for next behavior?
```
## Meta-Principle
```
TDD is a DESIGN technique, not a testing technique.
The cycle never changes: RED → GREEN → REFACTOR → Repeat
Writing tests first forces you to think about:
- What behavior do I need?
- How will I know it works?
- What's the simplest implementation?
This produces better-designed, more maintainable code.
```
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.