liveBook · Manning

Integration test

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

Integration testing evaluates how multiple software components work together through their real interfaces and interactions.

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

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Works through starting a service, loading a database fixture, sending HTTP requests, checking responses, and shutting down; does not explore test-framework internals.
Examples
Tests a metadata microservice’s /videos route using Jest, Axios, a real HTTP server, and MongoDB test data.
What it assumes
Assumes a runnable microservice and installed test dependencies; builds on the distinction between unit tests and integrated tests.
What you can do after
Apply it via Jest to start and stop a microservice, exercise its HTTP interface, and check responses against a test database.
How it connects
Relates integration testing to unit testing, mocking, end-to-end testing, HTTP, and the testing pyramid.

Also explained in

Compare how 31 books explain integration test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.