| description | Build tests outside-in: describe behavior first, grow tests red-green, keep what states behavior, and remove the scaffolding before landing. |
|---|
Test-driven development works well for agents. The trouble comes after green. Each step leaves a small test behind, and the pile grows into test sediment. Sediment slows every build and change. It breaks on refactors that keep behavior. It can lock in wrong behavior, so a bug fix means defending the old wrong answer first.
OpenClaw's test-audit skill cleans up a pile that already exists. Use it for audits. This skill keeps the pile from forming: describe behavior from the outside, grow tests red-green, keep what states behavior, and remove the rest before landing.
One complete set of outside-in tests that verify the behavior of the working software. No duplicates and no tautologies. Each test makes one claim no other test makes, and each can fail for the reason its name gives.
- Test each behavior where the user or caller meets it: the command line, the API or the screen. State it in the caller's words.
- Care little about the layers underneath. They may change while the behavior holds.
- Test something inside directly only when it owns behavior worth stating alone, such as a parser. Its interface is then its outside.
- Give each behavior one owning test. A bug gets one regression test where it shows, not one at every layer it crosses.
Write behaviors as given, when, then, in the user's words, before any code. Given a customer with a paid order, when they ask for a refund, then the order shows a pending refund.
- A brief that lists behaviors this way hands an agent its outside-in tests.
- Example tables, as in Cucumber's scenario outlines, become edge-case tables.
- The shape is the value. Glue code between plain-language steps and the system can become sediment too, so keep it thin or skip the tool.
- Write the behavior as an outside-in test. Watch it fail for the right reason.
- When a step is hard, drop to unit tests. They are scaffolding for the work in progress.
- Make it pass.
- Before landing, keep a test only if it is one of the four kinds below. Delete the rest.
- Behavior tests through the real entry point.
- Edge-case tables: boundaries, empty input, bad input and limits in one table.
- Contract checks on what others depend on: schemas, output formats, secrecy, releases.
- Regression tests that failed on the code before the fix.
These questions come from OpenClaw's test-audit. A missing answer means do not add it.
- What behavior does it protect?
- What credible mistake makes it fail?
- Why does no existing test catch that?
- Does it need a hook, export or flag only tests use? Then move it to a real boundary.
OpenClaw's skill lists the junk patterns in full. Agents miss these most:
- A test asserts what its own setup made true.
- One claim is tested at several layers.
- A refactor that keeps behavior breaks many tests.
- A bug fix needs test edits that defend the old wrong answer.
- Tests are named for tickets or steps, not behaviors.
- Coverage counts lines run, not claims checked. A tautological test raises coverage and checks nothing. Use coverage as a map of what is untested.
- Delete with evidence, not by category. Mutation testing shows which tests catch mistakes nothing else catches.
- Never delete the only test of a behavior. Write the outside-in test, then delete.
- Slow or old is no reason to delete. Redundant or tautological is.
- A kept test that fails may have found a product bug. Fix the code, not the test.
- Do not let cleanup become its own proof spiral. Remove in small batches, run the suite, land.