tdd
Implement changes using Test-Driven Development (Red-Green-Refactor). Use for bug fixes, new features, or any code change that should have test coverage.
Best use case
tdd is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Implement changes using Test-Driven Development (Red-Green-Refactor). Use for bug fixes, new features, or any code change that should have test coverage.
Teams using tdd should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/tdd/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How tdd Compares
| Feature / Agent | tdd | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Implement changes using Test-Driven Development (Red-Green-Refactor). Use for bug fixes, new features, or any code change that should have test coverage.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
SKILL.md Source
# TDD Implement code changes using strict Red-Green-Refactor. Iron law: **no production code without a failing test first.** Wrote code before a test? Delete it. Start over from a failing test. ## Available skills and subagents - **`/e2e`** — Use when the change needs a Playwright E2E test instead of a unit test. - **`/verify`** — Run after completing all TDD cycles to ensure everything passes across the monorepo. ## When to use - Bug fixes — write a test that reproduces the bug before fixing - New functions, methods, or utilities - Refactoring existing logic that lacks tests **Skip** for: pure UI components (we don't test React components), config files, generated code. ## Determine test scope - **Go unit** (`apps/backend/`): test file next to source as `*_test.go`. Run: ```bash cd apps/backend && go test -v -run TestName ./internal/path/to/package/... ``` - **TypeScript unit** (`apps/web/lib/`): test file next to source as `*.test.ts`. Run: ```bash cd apps && pnpm --filter @kandev/web test -- --run path/to/file.test.ts ``` - **Web E2E** (`apps/web/e2e/`): delegate to `/e2e` for Playwright tests. Choose the right level: unit tests for isolated logic, E2E for user-facing flows. ## Steps ### 1. RED — Write a failing test 1. Identify the single behavior to implement or bug to reproduce 2. Write the **smallest test** that asserts the expected behavior — one assertion, clear name 3. Run the test and confirm it **fails with the expected assertion error** (not a compile/import error) 4. If it passes immediately, the test is not testing new behavior — revise it ### 2. GREEN — Minimal code to pass 1. Write the **minimum production code** to make the failing test pass 2. Do not add extra logic, handle other edge cases, or refactor yet 3. Run the test again and confirm it **passes** 4. If it fails, fix the production code (not the test) ### 3. REFACTOR — Clean up 1. Improve production code: extract helpers, rename, simplify — without changing behavior 2. Improve tests: table-driven tests (Go) or `describe`/`it` blocks (TS), remove duplication 3. Run the test after each change to confirm still green ### 4. Repeat Return to step 1 for the next behavior or edge case. Continue until the feature or fix is complete. ### 5. Final verification Run `/verify` to ensure all formatters, linters, typechecks, and tests pass across the monorepo. ## Testing anti-patterns **Don't test mock behavior:** - If your assertion checks a mock element (`*-mock` test ID, mock return value), you're testing the mock, not the code. Test real behavior or don't mock it. **Don't add test-only methods to production code:** - `destroy()`, `reset()`, `_testHelper()` that only tests call — put these in test utilities, not production classes. **Mock minimally and understand dependencies:** - Before mocking, ask: what side effects does the real method have? Does the test depend on any of them? - Mock the slow/external part (network, disk), not the method the test depends on. - If mock setup is longer than test logic, consider an integration test instead. **Don't use incomplete mocks:** - Mock the complete data structure as it exists in reality, not just fields your test uses. Partial mocks hide bugs when downstream code accesses omitted fields. **Never swallow errors in tests:** - `try/catch` that silently ignores failures in test helpers or setup — these hide real failures. ## Red flags - Writing production code before a failing test exists — delete and start over - Test passes on first run — it tests nothing new, revise the test - Fixing a test to make it pass instead of fixing the production code - Large jumps — multiple behaviors implemented between test runs - Skipping the refactor step - Mock setup longer than test logic — consider integration test - Asserting on mock elements instead of real behavior
Related Skills
verify
Run format, typecheck, test, and lint across the monorepo. Use after implementing changes.
spec
Write a feature spec — the "what & why" of a kandev product feature, before coding. Use when the user says "let's spec X" or starts a new product feature.
simplify
Simplify recently changed code — inline one-off abstractions, remove speculative code, reduce nesting, replace cleverness with clarity. Run after implementing a feature.
record
Record an architectural decision (ADR) or save an implementation plan. Use after making significant design choices or completing features.
qa
Verify a feature works after implementation. Actively try to break it — edge cases, error paths, integration wiring, and real usage flows.
push
Commit and push to the current branch. Use --fixup to also wait for CI/CodeRabbit and fix issues.
pr
Commit, push, and create a PR. Default is ready-for-review with auto-fixup. Use --draft to skip review/fixup.
pr-fixup
Wait for CI checks and automated reviews (CodeRabbit, Greptile, Claude) on a PR, fix failures and address comments, then push.
playwright-cli
Automate browser interactions, test web pages and work with Playwright tests.
fix
Fix bugs and issues — reproduce, find root cause, minimal fix with regression test. Use when something is broken.
feature
Guided feature development — brainstorm, explore codebase, design architecture, implement with TDD, and review. Use for new features or significant changes.
e2e
Write and run web E2E tests (Playwright) using TDD — locations, patterns, commands, and debugging.