跳到主要内容
知仓学习社ZHICANG

test-driven-development

RED-GREEN-REFACTOR cycle with strict phase gates for TDD.

不碰外部(只输出文字)无严重或高危命中notque/vexjoy-agent

它会碰到什么

扫了多少5 个文本文件,39 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Test-Driven Development (TDD) Skill

Enforce the RED-GREEN-REFACTOR cycle for all code changes. Tests are written before implementation code, verified to fail for the right reasons, and maintained through disciplined development cycles.

Reference Loading Table

| Signal | Load These Files | Why |

|---|---|---|

| errors, error handling | error-handling.md | Loads detailed guidance from error-handling.md. |

| full RED-GREEN-REFACTOR walkthroughs in Go, Python, JavaScript | examples.md | Loads detailed guidance from examples.md. |

| detailed phase steps, rationale, or language-specific test commands | phase-guidance.md | Loads detailed guidance from phase-guidance.md. |

Instructions

Before starting any TDD cycle, read and follow repository CLAUDE.md files. Project instructions override default TDD behaviors because local conventions (test frameworks, directory layout, naming) vary across codebases.

Full phase guidance (steps, rationale, code examples, language commands) lives in [references/phase-guidance.md](references/phase-guidance.md). Load it when you need detailed instructions or examples. The sections below are the lean phase skeleton plus the mandatory gates.

Phase 1: Write a Failing Test (RED)

Write a test that describes the desired behavior before any implementation exists. Use specific assertions, descriptive names, Arrange-Act-Assert pattern, and one concept per test. Run the test and show full output. Details: [references/phase-guidance.md](references/phase-guidance.md).

RED Phase Gate

Proceed to the GREEN phase only after all of these are true:

  • [ ] Test file is created and saved
  • [ ] Test has been executed
  • [ ] Test output shows FAILURE (not syntax/import error)
  • [ ] Failure message indicates missing implementation

Phase 2: Verify Failure Reason (RED Verification)

The test must fail because the feature is not implemented, NOT because of syntax errors, import errors, wrong test setup, or unrelated failures. Expected patterns per language and recovery steps: [references/phase-guidance.md](references/phase-guidance.md).

Phase 3: Implement Minimum Code (GREEN)

Write ONLY enough code to make the failing test pass. No extra features. Hardcoded values are OK initially. Over-engineering and correct examples: [references/phase-guidance.md](references/phase-guidance.md).

Phase 4: Verify Test Passes (GREEN Verification)

Run the test and the full suite; show complete output. Never summarize. Debug guidance: [references/phase-guidance.md](references/phase-guidance.md).

GREEN Phase Gate

Proceed to the REFACTOR phase only after all of these are true:

  • [ ] Implementation code is written
  • [ ] New test has been executed and shows PASS
  • [ ] Full test suite has been executed
  • [ ] No other tests have been broken

Phase 5: Refactor (REFACTOR)

Improve code quality without changing behavior. Establish a green baseline first, refactor incrementally, run tests after every step. Test behavior, not internals. Decision criteria table and behavior-vs-internals examples: [references/phase-guidance.md](references/phase-guidance.md).

REFACTOR Phase Gate

Mark the task complete only after all of these are true:

  • [ ] All refactoring changes are saved
  • [ ] Full test suite has been executed
  • [ ] ALL tests pass (not just the new one)
  • [ ] Code quality has been evaluated against the criteria table above

Phase 6: Commit

Commit the test and implementation together as an atomic unit. Run the full suite, commit with a descriptive message, clean up temporary files. Report facts without self-congratulation.

Cycle Discipline

Each feature gets its own RED-GREEN-REFACTOR cycle. Do not batch multiple features into one cycle. Wrong-vs-correct cycle examples: [references/phase-guidance.md](references/phase-guidance.md).

Reference Material

  • [references/phase-guidance.md](references/phase-guidance.md) — Full phase steps, rationale, code examples, Arrange-Act-Assert, optional techniques, language-specific testing commands
  • [references/error-handling.md](references/error-handling.md) — Symptoms, causes, and solutions for stuck cycles (passes too early, wrong failure reason, green-but-broken, refactor breakage)
  • [references/examples.md](references/examples.md) — Language-specific TDD examples (Go, Python, JavaScript)

Error Handling

Load [references/error-handling.md](references/error-handling.md) when a cycle is stuck. It covers: test passes before implementation, test fails for wrong reason, tests pass but feature does not work, refactoring breaks tests.

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 419
本站分层T2
该仓技能数122
原文件路径skills/testing/test-driven-development/SKILL.md

同一个仓库里的其他技能

看这个仓库的全部 122 个技能