最初にテストを実行せよ
コーディングエージェントを使用する際、自動テストは必須であり、従来の「時間とコストがかかる」という言い訳は通用しない。
キーポイント
AIコーディングエージェントの実践において、テストの自動実行が必須のエンジニアリングパターンとして提案されている
既存のテストスイートはエージェントがコードベースを理解し、品質を維持するための重要なツールとして機能する
「最初にテストを実行する」という4単語のプロンプトが、エージェントのテスト指向マインドセットを形成する効果的な手法として紹介されている
AI生成コードの信頼性確保において、テスト実行が従来以上に重要な役割を果たすことが強調されている
影響分析・編集コメントを表示
影響分析
この記事は、AIコーディングエージェントの実用的な導入方法を具体的に示しており、開発現場での実践的な価値が高い。テスト駆動開発の原則をAIエージェントワークフローに組み込む方法論を提供することで、AI支援開発の品質保証プロセスを強化する可能性がある。
編集コメント
AIエージェントの実践的活用において、テストの重要性を再認識させる内容。具体的なプロンプト例が現場での即時適用を可能にしている点が実用的。
最初にテストを実行せよ - エージェント型エンジニアリングパターン - Simon Willison's Weblog Simon Willison’s Weblog
ガイド > エージェント型エンジニアリングパターン
最初にテストを実行せよ
コーディングエージェントを扱う際、自動化されたテストはもはや任意のものではなくなった。
コードベースが急速に進化している間は、テストを書くのに時間がかかり、頻繁に書き直すのはコストが高いという、テストを書かないための古い言い訳は、エージェントがわずか数分でテストを整えてくれるようになった今、もはや通用しない。
また、AIが生成したコードが主張する通りの動作をすることを保証するためにも、テストは不可欠だ。コードが一度も実行されていないなら、本番環境にデプロイしたときに実際に動作するかどうかは純粋に運次第である。
テストはまた、エージェントが既存のコードベースに迅速に慣れるのを助ける優れたツールでもある。Claude Codeや類似のエージェントに既存の機能について尋ねたときに何が起こるか観察してみよ。エージェントが関連するテストを見つけて読み込む可能性は非常に高い。
エージェントはすでにテストに対してバイアスを持っているが、既存のテストスイートの存在は、ほぼ確実にエージェントが自身で行った新しい変更をテストする方向に押しやるだろう。
私が既存のプロジェクトに対してエージェントで新しいセッションを開始するときはいつでも、次のようなバリエーションのプロンプトから始める:
最初にテストを実行せよ
私のPythonプロジェクトでは、pyproject.tomlを設定してあるので、代わりにこうプロンプトできる:
"uv run pytest" を実行せよ
この4語のプロンプトはいくつかの目的を果たす:
エージェントにテストスイートが存在することを伝え、テストの実行方法を理解することを強制する。これにより、エージェントが将来、何も壊していないことを確認するためにテストを実行することはほぼ確実になる。
ほとんどのテストハーネスは、エージェントにおおよそのテスト数を示す。これはプロジェクトの規模と複雑さの代理指標として機能し、またエージェントがさらに学びたいならテスト自体を検索すべきであることをほのめかす。
エージェントをテスト志向のマインドセットに置く。テストを実行した後では、エージェントが後で自身のテストでそれを拡張するのは自然なことだ。
「赤/緑TDDを使用せよ」と同様に、「最初にテストを実行せよ」という4語のプロンプトは、モデルにすでに組み込まれている相当量のソフトウェアエンジニアリングの規律を包含している。
これはガイド「エージェント型エンジニアリングパターン」の1章である。
本ガイドの章
コードを書くことは今や安価だ
テストと品質保証 赤/緑TDD
最初にテストを実行せよ
前へ: 赤/緑TDD
原文を表示
First run the tests - Agentic Engineering Patterns - Simon Willison's Weblog Simon Willison’s Weblog
Guides > Agentic Engineering Patterns
First run the tests
Automated tests are no longer optional when working with coding agents.
The old excuses for not writing them - that they're time consuming and expensive to constantly rewrite while a codebase is rapidly evolving - no longer hold when an agent can knock them into shape in just a few minutes.
They're also vital for ensuring AI-generated code does what it claims to do. If the code has never been executed it's pure luck if it actually works when deployed to production.
Tests are also a great tool to help get an agent up to speed with an existing codebase. Watch what happens when you ask Claude Code or similar about an existing feature - the chances are high that they'll find and read the relevant tests.
Agents are already biased towards testing, but the presence of an existing test suite will almost certainly push the agent into testing new changes that it makes.
Any time I start a new session with an agent against an existing project I'll start by prompting a variant of the following:
First run the tests
For my Python projects I have pyproject.toml set up such that I can prompt this instead:
Run "uv run pytest"
These four word prompts serve several purposes:
It tells the agent that there is a test suite and forces it to figure out how to run the tests. This makes it almost certain that the agent will run the tests in the future to ensure it didn't break anything.
Most test harnesses will give the agent a rough indication of how many tests they are. This can act as a proxy for how large and complex the project is, and also hints that the agent should search the tests themselves if they want to learn more.
It puts the agent in a testing mindset. Having run the tests it's natural for it to then expand them with its own tests later on.
Similar to "Use red/green TDD", "First run the tests" provides a four word prompt that encompasses a substantial amount of software engineering discipline that's already baked into the models.
This is a chapter from the guide Agentic Engineering Patterns.
Chapters in this guide
Writing code is cheap now
Testing and QA Red/green TDD
First run the tests
Previous: Red/green TDD
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み