Dev.to
7/10/2026

Lesson 1 - TDD with AI: getting tests that hold up when the agent writes them
Short summary
A developer shares lessons from letting an AI coding agent write tests that passed but broke on every code change due to excessive mocking and wiring assertions. The fix: use shared object factories with real models instead of mocks, and assert behavior rather than function calls. The key insight is that coding agents optimize for passing tests unless explicitly told to optimize for test durability.
- •AI-generated tests passed initially but broke on every model change due to excessive mocking
- •Solution: replace inline mocks with shared factories using real models, assert behavior not call wiring
- •Coding agents are agreeable by default — you must explicitly ask for tests that survive change
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



