Testing Strategy Shift
From tests after implementation to tests that drive AI-assisted implementation.
Most developers know TDD, but many still implement first and test later. In the AI era, this order becomes more costly because tests can serve as the instruction sheet for AI.
Flow Change
| Problem in old flow | AI-era fix |
|---|---|
| Tests mirror implementation | Tests define behavior first |
| Testing feels like extra work | Tests become task instructions |
| Edge cases are missed twice | Edge cases are listed before implementation |
| Refactors break implementation-bound tests | Behavior tests survive refactors |
Behavior Tests Beat Implementation Tests
Implementation-bound:
test('DiscountService reads from a Map', () => {
const service = new DiscountService(new Map([['VIP10', 0.1]]))
expect(service.calculateDiscount('VIP10', 10000)).toBe(9000)
})Behavior specification:
describe('discount calculation', () => {
test('applies a valid coupon', () => {
const result = applyDiscount({ code: 'VIP10', amount: 10000 })
expect(result.finalAmount).toBe(9000)
expect(result.discountApplied).toBe(true)
})
test('rejects expired coupons', () => {
const result = applyDiscount({ code: 'EXPIRED', amount: 10000 })
expect(result.finalAmount).toBe(10000)
expect(result.discountApplied).toBe(false)
})
})The second version lets AI choose the implementation while humans own the behavior.
Practical Workflow
- Write business rules as tests.
- Ask AI to implement code that passes those tests.
- Run the test suite.
- Add missing edge cases.
- Ask AI to adjust implementation without weakening tests.
- Review security, performance, and integration behavior.
The Dangerous Pattern
Never let AI only test its own assumptions
If AI writes code and then writes tests for that same code, the tests may validate the bug. Ask AI to propose test cases, but humans should own the behavior and acceptance criteria.
What Humans Should Test First
| Area | Why |
|---|---|
| Business rules | AI cannot infer local policy unless explicit |
| Authorization and permissions | Missing checks are high impact |
| Failure and retry paths | AI often optimizes for happy paths |
| Concurrency and idempotency | Local examples hide race conditions |
| Boundary values | Tests make assumptions visible |
Next
Read Debugging Habit Reset to apply the same specification mindset to failures.