Performance: Integration vs unit test decision
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 |
request(app)
.get('/users')
.expect(200)
.end((err, res) => {
if (err) throw err;
console.log(res.body.length);
});
What type of test is this and what does it check?Pass the test and this pattern moves unknown