ワンクリックで
tdd-workflow
Detailed Red-Green-Refactor TDD protocol with edge cases, anti-patterns, and test runner detection
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Detailed Red-Green-Refactor TDD protocol with edge cases, anti-patterns, and test runner detection
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | tdd-workflow |
| description | Detailed Red-Green-Refactor TDD protocol with edge cases, anti-patterns, and test runner detection |
Identify the project's test runner by examining these files:
| File | Likely Runner | Command |
|---|---|---|
package.json | Jest, Vitest, Mocha, Node test runner | npm test or check scripts |
pyproject.toml | pytest | pytest or python -m pytest |
setup.cfg / pytest.ini | pytest | pytest |
tox.ini | tox (wrapping pytest/unittest) | tox |
go.mod | Go testing | go test ./... |
Cargo.toml | Rust test | cargo test |
Makefile | Check for test target | make test |
build.gradle | JUnit via Gradle | gradle test |
pom.xml | JUnit via Maven | mvn test |
Gemfile | RSpec or Minitest | bundle exec rspec / rake test |
.csproj | xUnit / NUnit / MSTest | dotnet test |
mix.exs | ExUnit | mix test |
deno.json | Deno test | deno test |
bun.lockb / bunfig.toml | Bun test | bun test |
When the runner is ambiguous (e.g., package.json exists but has no test script),
check for config files like jest.config.*, vitest.config.*, .mocharc.*,
or test directories named __tests__, test, tests, spec.
A good test in the RED phase should:
test_empty_stack_raises_on_pop, should return 404 when user not found.AttributeError: 'Stack' has no attribute 'pop'
or expected 404 but got undefined), not that the test itself has a syntax error.When the simplest passing implementation would be to hardcode a return value, write a second test with different inputs to force the general solution. This is called triangulation.
Example:
add(1, 2) should return 3 -> Implement: return 3 (hardcoded)add(3, 4) should return 7 -> Now forced to implement: return a + bIn the GREEN phase:
Common refactorings to consider in the REFACTOR phase:
Always run the full test suite after refactoring. If any test fails, revert the refactoring -- do not "fix" tests to match refactored code.
The behavior is already implemented. This means either:
You likely changed too much. Revert to the last committed state and take a smaller implementation step. The goal is to change the minimum code to make exactly one test go from red to green without breaking any existing tests.
This is why we commit after the GREEN phase. If refactoring goes wrong, you can always revert to the last green commit. Consider making multiple small refactoring commits rather than one large one.
When modifying existing code that has no tests:
If a test passes sometimes and fails other times:
| Anti-Pattern | Why It Is Harmful | What to Do Instead |
|---|---|---|
| Writing implementation first, then tests | Tests become after-the-fact verification, miss edge cases, and don't drive design | Always write the test first |
| Writing multiple tests before any implementation | Loses the tight feedback loop; you don't know if each test is testing what you think | Write one test, make it pass, repeat |
| Gold-plating the implementation | Adds untested behavior, increases complexity | Write only what the current test demands |
| Skipping the REFACTOR phase | Technical debt accumulates; code becomes harder to change | Always evaluate, even if you decide no changes are needed |
| Modifying tests to match broken implementation | Hides bugs, breaks the safety net | Fix the implementation, not the test |
| Testing private/internal methods | Creates brittle tests coupled to implementation details | Test through the public API |
| Large increments | Makes failures hard to diagnose, increases risk | Break into the smallest possible steps |
| Not running the full suite | Can miss regressions in other parts of the code | Always run all tests, not just the new one |
| Skipping commits after GREEN | Loses safe revert points | Commit every passing state |
Follow Conventional Commits format:
test: add test for <behavior> -- when committing only test codefeat: implement <behavior> -- when committing test + implementationfix: correct <bug description> -- when fixing a bug with TDDrefactor: <what was improved> -- when committing refactoring changesEach commit after the GREEN phase should represent a complete, passing state of the code. The commit message should describe the behavior that was added, not the implementation detail.