Software Engineering 2026

TDD with AI

TDD Red/Green Cycle

Flowchart

TDD matters more with agents, not less. The test is the definition of correct, and the definition of correct is the part a human has to own. Let agents write implementations freely. Be deliberate about who writes the tests for critical behavior.

RED/GREEN workflow:

  1. Write a failing test (RED)
  2. Implement the minimum to pass (GREEN)
  3. Refactor with tests green
  4. Next test

The failure to watch for: agents "fixing" a failing test by editing the test. Protect test files in review, or block test edits during implementation with a hook.

For AI-powered features, tests become evals: see Eval.

Example TDD prompts:

Starting TDD:
"Implement a discount calculator test-first. Failing tests for:
- Percentage discounts (10% off $100 = $90)
- Fixed discounts ($15 off $100 = $85)
- Minimum purchase requirements
- Stacking multiple discounts
Make them fail first."

RED:
"Write a failing test for user registration:
- Valid email/password creates a user
- Duplicate email returns 409
- Weak password returns 400 with a specific message
Don't implement yet."

GREEN:
"The test fails as expected. Implement the minimum to pass.
Don't change the tests. No extra features."

Refactor:
"All tests pass. Extract validation to its own function, remove duplication,
improve naming. Run tests after each change."

From a user story:
"Story: 'As a user, I can reset my password via email.'
Integration tests for: request reset, valid token, expired token, invalid token."

Team standards: shared fixtures and test-data builders, so agent-written tests look like the rest of the suite and reviewers can read them quickly.