An integration test checks code working together rather than a function in isolation. For a microservice, that usually means starting the whole service, including its modules and libraries, and using its normal interface. This can reveal problems between modules that isolated unit tests miss. section 9.7
To test a microservice through HTTP:
- Start its real dependencies. If it uses MongoDB, run a test database and load realistic test data instead of substituting a mock. section 9.7.2 section 9.7.4
- Use Jest’s beforeAll to start the service as an HTTP server. Send requests with Axios, then check the responses. section 9.7.4
- Use afterAll to close the service. Run the test with npx jest, or npm test when that command is configured in package.json. section 9.7.4 section 9.7.5
Test a metadata service
Start the metadata microservice against a MongoDB test database, load a fixture, and request its /videos route through HTTP. Check the response rather than calling the route’s code directly. Keep this test away from production data: the fixture loader first deletes the database. section 9.7.4
Integration tests cover more code per test than unit tests, but a real server and database make them slower. Keep more unit tests than integration tests, and fewer end-to-end tests still. The boundaries between these test types are not absolute. section 9.7.6 section 9.8.7






























