Manuals / AI Coding with Cursor / Chapter 6
B · Review & Test · intermediate · ~35 min · Chapter 6 of 11
Test-driven prompting
Write tests first, then ask the agent to make them pass. TDD + AI = fewer hallucinated implementations.
Path progress50%
Step 1 of 2
Test-first workflow
1) Write failing test. 2) Brief agent: "Make this test pass. Do not change the test." 3) Review. 4) Refactor.
Example
// You write this test first:
import { describe, it, expect } from 'vitest'
import { formatCurrency } from './format'
describe('formatCurrency', () => {
it('formats USD with 2 decimals', () => {
expect(formatCurrency(1234.5, 'USD')).toBe('$1,234.50')
})
it('handles zero', () => {
expect(formatCurrency(0, 'USD')).toBe('$0.00')
})
})
// Then brief agent: "Implement formatCurrency to pass these tests."Do this now
Write a failing test for a utility function. Agent makes it pass.
Was this step clear?
Chapter learning outcomes
- TDD with agents
- Test-first briefs
- Red-green-refactor
Clear these before you leave
Side quest
Page object TDD
Write a Playwright test first. Agent builds the page object.