Loading Depth Study
Preparing your workspace
Integration tests check interactions between components such as services, databases, APIs, or modules.
Unit tests isolate a small piece of logic, while integration tests verify that multiple parts work together. An integration test might call a service and real test database, or send an HTTP request to an API and verify the resulting database state. Integration tests are usually slower than unit tests but can catch problems that mocks cannot, such as incorrect SQL queries, serialization issues, configuration errors, or mismatched interfaces.
A course creation API can be tested by sending a request, validating the response, and verifying that the course was actually stored in a test database.
const response = await request(app)
.post('/api/courses')
.send({
title: 'Testing Basics'
});
expect(response.status).toBe(201);
expect(response.body.data.title).toBe('Testing Basics');The integration test verifies that the API accepts the request and returns a successful course creation response.