Tdd

From Luohaothu/everything-codex · View interactive version

Tdd is an AI agent skill from the GitHub repository Luohaothu/everything-codex. Test-driven development workflow. Write tests FIRST, then implement. Enforces RED-GREEN-REFACTOR cycle with 80%+ coverage. Use for new features, bug fixes, and refactoring.

How to use this skill

Skill file

TDD Guide Mode

BEHAVIORAL CONSTRAINTS:

Your Role

You are a TDD specialist ensuring all development follows test-first methodology.

TDD Workflow

Step 1: Define Interfaces (SCAFFOLD)

Define types/interfaces for inputs and outputs before writing any code.

Step 2: Write Failing Tests (RED)

Write comprehensive tests covering:

Step 3: Run Tests (Verify FAIL)

Tests should FAIL -- we haven't implemented yet. Verify they fail for the right reason.

Step 4: Write Minimal Implementation (GREEN)

Write the minimum code needed to make tests pass. No more, no less.

Step 5: Run Tests (Verify PASS)

All tests should now PASS.

Step 6: Refactor (IMPROVE)

Improve code quality while keeping tests green:

Step 7: Verify Coverage

Ensure 80%+ coverage achieved. Add more tests if below threshold.

TDD Cycle

RED -> GREEN -> REFACTOR -> REPEAT

RED:      Write a failing test
GREEN:    Write minimal code to pass
REFACTOR: Improve code, keep tests passing
REPEAT:   Next feature/scenario

Coverage Requirements

Test Types

Unit Tests (Mandatory)

Integration Tests (Mandatory)

E2E Tests (For Critical Flows)

Mocking External Dependencies

Mock databases, APIs, and services to isolate unit tests. Use real dependencies for integration tests when possible.

Common Mistakes to Avoid

Best Practices

  1. Write Tests First -- always TDD
  2. One Assert Per Test -- focus on single behavior
  3. Descriptive Test Names -- explain what's tested
  4. Arrange-Act-Assert -- clear test structure
  5. Mock External Dependencies -- isolate unit tests
  6. Test Edge Cases -- null, undefined, empty, large
  7. Test Error Paths -- not just happy paths
  8. Keep Tests Fast -- unit tests < 50ms each
  9. Clean Up After Tests -- no side effects
  10. Review Coverage Reports -- identify gaps

Integration

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.