liveBook · Manning

Test container

As explained in gRPC Microservices in Go

A test container is a disposable containerized environment that provides an isolated real dependency for automated tests.

A test container is a disposable containerized environment that supplies an isolated real dependency for automated tests. It is especially useful when an integration test must exercise a service against a real database instead of a mock. section 7.6 section 7.2.2

Use test containers when the integration boundary matters, while weighing their operational cost against mocking.

  • Spin up the dependency, provide its credentials to the service under test, and execute scenarios against the real instance. section 7.2.2
  • Prefer mocks when preparing real dependencies would slow feedback and the test does not need to verify the integration itself. section 7.2.2
  • Use suite setup and teardown to create required components before integration tests and destroy them afterward. section 7.6

End-to-end order flow

Define the application stack in Docker Compose, provide Dockerfiles for each service, run the stack through test containers during SetupSuite, and destroy it during TearDownSuite. Use mysql:8 for the database and mount SQL that creates the payments and orders databases before testing the create-order flow. section 7.4.1

Figure 7.6 Application stack that test suite runs against

The application-stack diagram shows the services and dependencies that the test suite runs against. section 7.4.1

How gRPC Microservices in Go covers it

How deep it goes
Explains setup, credentials, Docker Compose, database initialization, and teardown, but does not detail the container library implementation.
Examples
Demonstrates a Docker Compose microservice stack with mysql:8, mounted SQL, and a create-order end-to-end test.
What it assumes
Assumes basic Docker familiarity and Go test-suite usage while contrasting real dependencies with mocked calls.
What you can do after
Apply it via Docker Compose and test suites to exercise services against disposable real dependencies.
How it connects
Connects integration testing, end-to-end testing, Docker Compose, mocking, test suites, and the test pyramid.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.