As a [role], I want to [action], so that [benefit]Example:As a user, I want to search for markets semantically,so that I can find relevant markets even without exact keywords.
3
Generate Test Cases
4
For each user journey, create comprehensive test cases:
5
describe('Semantic Search', () => { it('returns relevant markets for query', async () => { // Test implementation }) it('handles empty query gracefully', async () => { // Test edge case }) it('falls back to substring search when Redis unavailable', async () => { // Test fallback behavior }) it('sorts results by similarity score', async () => { // Test sorting logic })})
6
Run Tests (They Should Fail)
7
npm test# Tests should fail - we haven't implemented yet
8
Implement Code
9
Write minimal code to make tests pass:
10
// Implementation guided by testsexport async function searchMarkets(query: string) { // Implementation here}
11
Run Tests Again
12
npm test# Tests should now pass
13
Refactor
14
Improve code quality while keeping tests green:
15
Remove duplication
Improve naming
Optimize performance
Enhance readability
16
Verify Coverage
17
npm run test:coverage# Verify 80%+ coverage achieved
// Resilient to changesawait page.click('button:has-text("Submit")')await page.click('[data-testid="submit-button"]')
No Test Isolation
Wrong:
// Tests depend on each othertest('creates user', () => { /* ... */ })test('updates same user', () => { /* depends on previous test */ })
Correct:
// Each test sets up its own datatest('creates user', () => { const user = createTestUser() // Test logic})test('updates user', () => { const user = createTestUser() // Update logic})