Performance: Integration vs unit test decision
MEDIUM IMPACT
This concept affects the development and test execution speed, impacting how quickly changes can be verified and how much resource usage tests consume.
test('getUsers returns user list', () => { const mockDb = { getUsers: () => [{id:1}, {id:2}] }; const users = getUsers(mockDb); expect(users).toHaveLength(2); });
test('GET /users returns users', async () => { const response = await request(app).get('/users'); expect(response.status).toBe(200); expect(response.body).toHaveLength(5); });
| Pattern | Test Speed | Resource Usage | Feedback Loop | Verdict |
|---|---|---|---|---|
| Integration Test (full stack) | Slow (100-300ms+) | High (DB, network) | Slow feedback | [X] Bad for frequent runs |
| Unit Test (isolated logic) | Fast (<1ms) | Low (no external calls) | Fast feedback | [OK] Good for frequent runs |