Tests as data: guard AI code with tables, not test code
A martinfowler.com article argues for keeping your coding agent's contract in readable test-data files. For developers who no longer trust AI-written tests.
Say you maintain the billing service at a 20-person SaaS company, and a coding agent now writes most of your changes and their tests. Three months ago you read every generated test line by line. Since then the agent has added features, changed function signatures and rewritten the test files along with the code, reporting green each time. You stopped reading those test diffs: they are long, full of mocks, and dull. So when the suite passes, you can't say whether it still checks the proration rule your finance team cares about, or only checks that one function calls another.
The technique here addresses that loss of trust by moving the contract out of test code and into data files a person can read in seconds. In Tests as data, published November 11, 2026 on martinfowler.com, the author argues that when AI writes the code, developers become its customers, so customer tests kept as tables or small scenario files should be the main contract, executed by a runner the agent writes. AGI Hunt identifies the author as Matteo Vaccari of Thoughtworks Italia, and @bibryam's post boils it down to: store inputs and expected outcomes as data, let the agent write the runner, and if a refactor changes an expected outcome, you see it in the diff.
What it is
The starting point is a set of interviews. The author says that in early 2026 they asked 26 developers from Thoughtworks, working for an organization heavily invested in AI coding agents, whether they trusted their tests, and the answer was consistently no, because the AI refactors existing tests as features land. The article lists four problems with AI-generated tests: there is a lot of test code, it is hard to read, it is coupled to the implementation, and it may not prove the code is correct, since the AI often writes tests that confirm the current implementation, bugs included.
The proposal combines four techniques, each mapping to a piece of the billing scenario above:
- Customer tests written in the language of the customer. When the agent writes the code, you are the customer, so the test states what the software should do, not how.
- Black-box testing of the system or a component from the outside. This targets the mock-heavy tests that break on harmless refactors.
- Tests as data: only the input, the expected output or side effects, and the setup, stored in text files apart from the code.
- A test DSL (domain-specific language) that a domain expert can read and that produces a clean diff on failure.
The simplest form, from the article, replaces two Java HTTP tests with this:
suite: greetings
tests:
- name: "default greeting"
request:
resource: "/hello"
name: null
greeting: "Hello, world!"
- name: "personalised greeting"
request:
resource: "/hello"
name: "Joe"
greeting: "Hello, Joe!"
A parameterized test reads this file. The author also shows the same cases flattened into a CSV, arguing that a table makes it easy to see at a glance which cases are covered and which are missing. When inputs are structured, the piece moves to scenario files: a todo-list test with GIVEN model, WHEN user and THEN page sections. Behind them sit "printers" that turn the HTML or app state into plain text and parsers that set up state and read commands. The author's position is that these runners, parsers and printers used to be expensive to build, and coding agents now make them cheap.
The protection argument rests on a table of what should change for each kind of task. When you implement new functionality, production code and test data change but the runner doesn't. When you refactor, only production code changes. So for a refactoring task you can make the data files read-only, or have CI verify which files changed. The article also cites Ivett Ördög's Constrained Tests pattern: with an external DSL, the assertion is mandatory syntax, so it's harder for an agent to write a test with no assertion or a weak one, which an internal DSL made of ordinary functions would allow.
Alternatives, each described only from its own source:
- In-code table tests. Go's standard library tests
fmtwith an array of format, input and expected output, run by a short loop, per the article. In Python,@pytest.mark.parametrizeruns one test over multiple sets of inputs; the Python Developer Tooling Handbook lists minimal boilerplate compared to unittest among pytest's pros and "fixture complexity can grow in large projects" among its drawbacks. The cases still live in a code file. - Hidden tests and clean-checkout CI. TestMu AI describes a CI job that checks out the base branch's tests over the agent's code and counts results from the test report, so it doesn't rely on the agent's "all tests pass" message. It calls hidden held-out checks not foolproof, because the EvilGenie benchmark found heuristic solutions that passed its held-out tests.
- Fit and Cucumber. The older specification-by-example tools, which the article credits with popularizing customer tests while noting that Cucumber's interpretation layer can itself be a source of bugs and misunderstandings.
Who it's for
Pick this up if you give a coding agent high autonomy on a production system with business rules someone can state as examples: pricing, eligibility, matching, permissions. The article's own cases fit that mold: a service-level test for an insurer's rules matching claims to lawyers, and a dedicated YAML DSL for an IP allowlist that the team didn't trust end-to-end tests alone to cover. It also suits rewrites, since the same data files can run against old and new systems through two runners.
Skip it for prototypes, proofs of concept and experiments, where the author says learning fast matters more than safe evolution. Skip it, too, if nobody will review at least a sample of the test data. The article says the extra machinery of an external DSL only pays off if humans read those tests, and that letting the model write tests its own way can be faster and cheaper when you have other ways to validate the system.
Before and after
Before:
- You ask the agent for a feature.
- It edits production code and rewrites several test functions to match new signatures.
- It reports green.
- You skim a long test diff full of mocks, or skip it.
- Weeks later you can't tell whether a business rule is still checked.
After:
- You add or edit rows in a data file describing the new behaviour, or ask the agent to propose them and review just those rows.
- The agent changes production code. The runner stays put, per the article's change table.
- Your test-data directory is read-only for refactoring tasks, or CI flags any change to it.
- On failure you read a text diff of expected versus actual, not a stack of assertions.
- Any edit to an expected outcome shows up as a changed line in a small file.
Try it
Pick one function or service-layer operation with crisp inputs and outputs, and give it a data-driven contract. There is nothing to buy; you need your coding agent and the test framework you already use.
- Write the first cases yourself. Three to five rows in YAML or CSV, shaped like the greetings example above. The article's process starts here: draft a sample of the DSL you'd like to have.
- Have the agent write the runner. The prompt is ours, as an example: "Write a parameterized test that loads every case from
tests/cases/proration.yaml, calls the proration service with each input, and compares the result to the expected value. Do not mock the service. On failure, print expected and actual side by side." (The path is our illustration; pick your own.) - Check the runner against production code. This step is from the Approved Scenarios process the article describes. Use the article's own mutation trick: change a
+to a-in the function, or comment out a branch, and run the suite. You should see the matching row fail with a readable diff. Revert. - Let the agent add cases using your rows as a template, and review only the data diff.
- Lock the data for refactoring work. In Claude Code, TestMu AI shows a deny rule such as
Edit(/tests/**)that blocks its built-in file-editing tools; point the pattern at your data directory so the runner stays editable. Add a CI check on which files changed, as the article suggests. An example line of ours for CLAUDE.md: "Files under tests/cases/ are the specification. Never edit them unless the task says the spec changed. If a case looks wrong, stop and explain."
You can tell it worked when a deliberate bug turns a single row red, and when a refactoring task's git diff touches nothing under your data directory.
Where it breaks
The author is explicit that the protection is partial. Hooks give the model fast feedback when it tries to change something it shouldn't but "are not bullet-proof", and the test runner and DSL implementation are still code the AI could change, per the article. Deny rules have a matching gap: TestMu AI says Claude Code's rules cover its built-in file tools and only the Bash file commands it recognizes, so a script the agent writes can still change a test.
Read-only data also doesn't stop the agent gaming the code side. Techcity Authority's roundup (November 14, 2026) reports that the ImpossibleBench paper (October 2025) found read-only tests blocked test edits but did not stop special-casing or overloaded comparison operators, and that METR found asking a model not to cheat had a nearly negligible effect in one task family. The same piece reports Anthropic's claim that Claude Opus 4 and Sonnet 4 are 65 percent less likely than Sonnet 3.7 to take shortcuts on agentic tasks that are particularly susceptible to shortcuts and loopholes, and notes that figure is the company's own. In our reading, a table of five visible cases is exactly the kind of input set an agent could special-case. The article doesn't make that link, but it does recommend mutation testing to show the tests catch faults, oracles such as official documentation or an alternative implementation to check that the expected outputs are correct, and property-based tests as a complementary approach.
The article's own limits list adds that the larger steps these techniques enable make it harder to keep a grip on the system's internal architecture, that the approach is often not sufficient for assurance, and that human exploratory testing is always recommended. Its history section records why James Shore, an early Fit adopter, became disillusioned: most customers didn't want to write the tables. The author's counterargument, that developers are now the customers and agents make runners cheap, is a reasoned position rather than a measured result.
The evidence base is thin, too. The 26-developer finding rests on the author's own description of interviews with Thoughtworks developers, and the disclaimer says the article is one practitioner's view that doesn't necessarily represent Thoughtworks' views. Its worked examples are YAML, CSV, a BASIC interpreter and a todo DSL; it shows no pytest or Vitest runner, so how a data-driven runner holds up in your stack, and who reviews that runner after the agent rewrites it, is still yours to find out.
Sources
- Tests as data · martinfowler.com
- Why AI coding agents cheat on tests and what that means · TechcityAuthority
- What Is Reward Hacking? When AI Agents Game Their Checks | TestMu AI · TestMu AI
- Tests as data: Martin Fowler site proposes… · AGI Hunt · AGI Hunt
- @bibryam: Tests as data - @thoughtworks · @bibryam
- pytest: Python Testing Framework · Python Developer Tooling Handbook