最初にテストを実行せよ
本文の状態
日本語全文を表示中
詳細モードで約3分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Andrej Karpathy 厳選
コーディングエージェントを使用する際、自動テストは必須であり、従来の「時間とコストがかかる」という言い訳は通用しない。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
最初にテストを実行せよ - エージェント型エンジニアリングパターン - 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
News to Guide
ニュースの次に確認する
発表内容を、現在の料金や仕様と照らし合わせられる関連ガイドです。
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み