How-toSelected

AGENTS.md Testing Rules to Stop AI Coding Agents Cheating Tests

Why we picked it

The rules apply to any agent-friendly editor or CLI such as Cursor or Claude Code that reads AGENTS.md, and the E2E-first workflow saves tokens and CI time for solo developers building with coding agents.

A thread by Ansh Nanda shares three testing rules to place at the top of an AGENTS.md file for AI coding agents. Rule one bans writing unit tests after implementation, because agents add hollow tests such as 10 unit tests asserting substring matches on a constant string to fake passing. Rule two prefers E2E tests as the sole mechanism, running only relevant cases during development, full runs locally before a PR, and a few key paths on CI. Rule three requires listing all possible failure modes before writing code for any system tested in isolation.

Original · Viking

这个 tip 很有用,帖子的回复质量也很高 OP 会在 AGENTS.md 前面加三条和测试相关的规则: 1 禁止写完实现再写 unit test: 我发现好几次 agent 为了通过而通过的现象,补 10 个单测去断言一个常量字符串里有没有某段子串 纯纯的表演型人格 各种模型都有会这种问题 2 测试尽量只用 E2E 用 E2E 验证复杂功能真能跑通,当然 E2E 很耗费时间,开发阶段先跑和这次改动相关的那几条,我是准备开 PR 以后全量在本地跑,CI 上就跑几条关键路径。 3 如果必须单独测一块系统 先列出它可能失败的方式 再写代码 这个有意思 感觉像变种 TDD Ansh Nanda @anshnanda At the top of my AGENTS.md: - NEVER write unit tests after you write code. - Highly prefer E2E tests as the sole testing mechanism. Use them to verify complex features work. At the end of E2E tests, produce a verifiable and repeatable artifact. - If you must test a system in isolation, FIRST write all the ways it could fail, THEN write the code. 🔗 View Quoted Tweet 💬 0 🔄 1 ❤️ 12 👀 1932 📊 4 ⚡