Other

Tests as data: ensuring AI-generated code does what we want

Martin Fowler Martin Fowler
Other

Martin Fowler publishes Matteo Vaccari's proposal for testing AI-generated code: treat customer tests stored as data, not code, as the contract between humans and coding agents, so refactors cannot silently weaken them.

Key points

  • Write customer tests, not unit tests, when agents generate the code: they state behaviour a non-programmer can read.
  • Tests-as-data keeps input, expected output and setup in YAML or CSV, so agents cannot quietly rewrite assertions in code.
  • Conventional AI unit tests lean on mocks and stubs, which break on harmless refactors and never prove correct results.
  • Prose specs in Markdown cannot be executed and LLMs often skip parts of them, so executable tests are the stronger contract.
  • Have the agent build a small runner for your test DSL, then add cases yourself; the YAML example keeps each case to name, input and expected output.
  • The techniques give agents the 'how to validate the result' they need, which works better than prescribing each implementation step.

Real-world use

  • A team using coding agents heavily that no longer trusts its test suite after repeated AI refactors of test code.
  • An HTTP endpoint whose greeting behaviour is pinned in a small CSV table of cases that anyone on the team can extend.
  • A spec-driven workflow where Markdown plans are replaced by executable customer tests that agents must satisfy.
  • End-to-end acceptance tests that need to stay readable and refactor-resistant while agents change the implementation.

This summary was generated by the agent from the original post on Martin Fowler. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message