赤/緑TDD
本文の状態
日本語全文を表示中
詳細モードで約2分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Andrej Karpathy 厳選
コーディングエージェントの結果を改善する簡潔な方法として、「赤/緑TDD」を使用することが提案されている。
Continue in AI NEW LAB
このニュースを、実務の判断につなげる
AI NEW LABで、試したことや先に確認したい条件を共有できます。まずはログインなしで読めます。
AI NEW LABで論点を見るSource Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
「レッド/グリーンTDD」は、コーディングエージェント(AIプログラミング支援ツール)の出力品質を向上させるための簡潔で効果的な手法である。TDD(テスト駆動開発)とは、コードを書く際に、その動作を証明する自動化されたテストを併せて作成する開発スタイルを指す。その中でも特に厳格な形式が「テストファースト開発」であり、これは実装コードより先に自動テストを書き、そのテストが最初に失敗することを確認した上で、テストが通るまで実装を繰り返し改善していくプロセスを取る。
この手法はコーディングエージェントとの相性が極めて良い。エージェントを使用する際の主なリスクは、動作しないコードを生成してしまうこと、あるいは不要で使われないコードを構築してしまうことにある。テストファースト開発は、これらの一般的な失敗を防ぐのに役立つ。まずテストを書くことで、エージェントが解決すべき問題と期待される動作を明確に定義できる。さらに、このプロセスにより堅牢な自動テストスイートが自然と構築され、プロジェクトが成長し、変更を加える際に既存機能が壊れてしまう「回帰」のリスクに対処できる。包括的なテストスイートは、機能を継続的に動作させ続ける最も効果的な手段である。
ここで「レッド/グリーン」という言葉が意味するのは、まさにこのプロセスの二つのフェーズである。「レッド」フェーズでは、実装前に書かれたテストが確かに失敗する(レッド)ことを確認する。このステップを省略すると、最初から通ってしまうテストを作成する危険があり、新規実装を正しく検証できなくなる。その後、「グリーン」フェーズでは、実装を進めてテストが通過する(グリーン)状態を目指す。
要するに「レッド/グリーンTDD」という簡潔な指示は、コーディングエージェントに対して、「テスト駆動開発を用い、まずテストを書き、実装前にそのテストが失敗することを確認し、その後テストが通るように変更を実装せよ」という長い指示の省略形として機能する。この明確なワークフローに従うことで、エージェントはより正確で必要十分なコードを生成し、結果として開発の生産性とコードベースの信頼性を高めることができるのである。
原文を表示
Red/green TDD - Agentic Engineering Patterns - Simon Willison's Weblog Simon Willison’s Weblog
Guides > Agentic Engineering Patterns
"Use red/green TDD" is a pleasingly succinct way to get better results out of a coding agent.
TDD stands for Test Driven Development. It's a programming style where you ensure every piece of code you write is accompanied by automated tests that demonstrate the code works.
The most disciplined form of TDD is test-first development. You write the automated tests first, confirm that they fail, then iterate on the implementation until the tests pass.
This turns out to be a fantastic fit for coding agents. A significant risk with coding agents is that they might write code that doesn't work, or build code that is unnecessary and never gets used, or both.
Test-first development helps protect against both of these common mistakes, and also ensures a robust automated test suite that protects against future regressions. As projects grow the chance that a new change might break an existing feature grows with them. A comprehensive test suite is by far the most effective way to keep those features working.
It's important to confirm that the tests fail before implementing the code to make them pass. If you skip that step you risk building a test that passes already, hence failing to exercise and confirm your new implementation.
That's what "red/green" means: the red phase watches the tests fail, then the green phase confirms that they now pass.
Every good model understands "red/green TDD" as a shorthand for the much longer "use test driven development, write the tests first, confirm that the tests fail before you implement the change that gets them to pass".
Build a Python function to extract headers from a markdown string. Use red/green TDD.
Here's what I got from Claude and from ChatGPT. Normally I would use a coding agent like Claude Code or OpenAI Codex, but this example is simple enough that both Claude and ChatGPT can implement it using their default code environments.
I did have to append "Use your code environment" to the ChatGPT prompt. When I tried without that it wrote the code and tests without actually executing them.
関連記事
News to Guide
ニュースの次に確認する
発表内容を、現在の料金や仕様と照らし合わせられる関連ガイドです。
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み