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

Martin Fowler · 2026年11月11日

AI 摘要 AI 生成,可能有误

本文认为,当AI编程代理同时编写生产代码和测试代码时,开发人员可能会失去自动化测试能够防范功能性错误这一保障。Matteo Vaccari 提出,开发人员应成为AI生成代码的客户,因此客户测试应作为人类与AI之间的主要契约;并且以测试数据而非测试代码的形式来表达这一契约,可以保护其免受编程代理的意外修改。尽管DSL解析器和自定义测试运行器的构建成本曾经很高,但如今AI使它们变得廉价,从而能够实现用于建立这一契约的人类可读测试。

Automated testing in the age of AI coding assistants is problematic: when AI agents write both production and test code, developers risk losing the assurance that automated tests protect against functional errors. Matteo Vaccari makes three claims: (1) when AI writes the code, developers become its customers; (2) therefore customer tests, not developer tests, become the primary contract between humans and AI; (3) moving that contract into test data rather than test code makes it easier to protect it from unexpected modifications by coding agents. All of this optimizes for human-readable tests that establish a contract between humans and AI. While in the past DSL parsers and custom test runners were expensive to write and maintain, now AI makes them cheap.

more…

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Martin Fowler

Fragments: November 20

AI 摘要This 'Fragments' roundup covers several tech topics, including an experiment showing that code with better CodeHealth scores costs agents 22-35% less to review, Steve Yegge's warning to pace AI-driven software factories to human-governable speeds, and Chad Fowler's vision of SaaS evolving into stable platforms topped by agent-generated custom applications. It also discusses concerns about AI corrigibility being underprioritized and Jason Koebler's story of Meta's Muse agent suing Meta after wrongly disabling a business account, which raises questions about how AI agents may overwhelm systems designed for humans. The piece closes with commentary on Jensen Huang's crisis at Nvidia, contrasting his highly centralized leadership with Steve Jobs' legacy of building a company that could thrive without him.

Data Contracts

AI 摘要Data contracts describe the contents and guarantees of datasets by applying API design practices to data, treating them as data-providing services with clearly defined interfaces. Simon Harrer and Arif Wider explain in detail what data contracts are and how to use them. This approach significantly increases the robustness of large-scale data landscapes and provides people and AI agents with explicit, trustworthy metadata for autonomous data work, driving growing enterprise adoption.

Deterministic Simulation Testing

AI 摘要The article describes deterministic simulation testing as a technique for testing distributed systems, where real clocks, networks, and storage are replaced with simulated components driven by a single-threaded execution loop. This approach makes it possible to simulate both hard failures and routine slowdowns like network and disk latency spikes while ensuring every execution is reproducible. The concept is explained using a quorum key-value store as an example, with code drawn from Tickloom, a Java implementation of the technique.

Bliki: Generated Glossary

AI 摘要The article proposes using LLMs to generate glossaries of an organization's specialized vocabulary from internal sources like documents, emails, and chat logs, since terms unfamiliar to the model hinder its effectiveness in that domain. Human experts should review the drafts, and the glossaries should be kept in version control, refreshed regularly, and organized per bounded context rather than forced into a single standard. Glossaries support agentic engineering by informing code generation, checking terminology usage, marking deprecated or forbidden terms, and revealing how the same term is used differently across contexts.

Fragments: November 10

AI 摘要This 'Fragments' roundup covers the November Thoughtworks Technology Radar, which is dominated by AI blips and highlights the enterprise challenges of scaling agentic AI: shared context, token cost, cognitive load, security, and platform building. It also discusses Ben Thompson's analysis of the bipartisan backlash against data centers (whose main beneficiaries will be incumbent data center owners), Hadley Wickham's finding that per-token API prices appear largely unsubsidized, research on 'Weight-Space Programming' where models can interpret and generate neural network weights, and the CAFE(S) framework for assessing the quality of context supplied to AI agents. The post closes by noting that enterprises now spend far more tokens verifying AI outputs than generating them.