Microservices Testing Strategies for Microservices 1 — Questions and Answers
Question 1: Which type of test verifies that two microservices can communicate correctly according to a shared contract, without requiring both services to be running simultaneously?
- End-to-end test
- Contract test (Correct answer)
- Integration test
- Smoke test
Correct answer: Contract test
Contract tests (e.g., using Pact) verify that a consumer and provider agree on the API interface, allowing each service to be tested independently against the recorded contract.
Question 2: In the microservices testing pyramid, which layer should contain the largest number of tests?
- End-to-end tests
- Service integration tests
- Unit tests (Correct answer)
- UI tests
Correct answer: Unit tests
Unit tests form the base and largest layer of the testing pyramid because they are fast, cheap to run, and provide immediate feedback on individual components.
Question 3: What is a 'test double' in the context of microservices testing?
- Running the same test twice to verify consistency
- A replica environment for load testing
- A replacement object (stub, mock, or fake) used in place of a real dependency (Correct answer)
- A secondary test suite that mirrors production tests
Correct answer: A replacement object (stub, mock, or fake) used in place of a real dependency
A test double is a generic term for any object that stands in for a real dependency during testing, including stubs, mocks, spies, and fakes.
Question 4: Which testing tool is most commonly associated with consumer-driven contract testing in microservices?
- JUnit
- Pact (Correct answer)
- Selenium
- Gatling
Correct answer: Pact
Pact is the leading tool for consumer-driven contract testing, allowing consumers to define expected interactions and providers to verify they meet those contracts.
Question 5: What is the primary goal of a 'component test' in a microservices architecture?
- Test the entire system end-to-end across all services
- Test a single microservice in isolation by replacing its external dependencies with test doubles (Correct answer)
- Test UI components in the browser
- Test inter-service network latency
Correct answer: Test a single microservice in isolation by replacing its external dependencies with test doubles
Component tests focus on a single microservice, replacing real external collaborators with stubs or mocks to verify the service's behavior in isolation.
Question 6: Which approach allows teams to test a new version of a microservice by routing a small percentage of real traffic to it while the old version handles the rest?
- Blue-green testing
- Canary testing (Correct answer)
- Shadow testing
- A/B testing
Correct answer: Canary testing
Canary testing routes a small fraction of live traffic to the new service version, allowing teams to detect issues in production conditions before full rollout.
Question 7: What is 'shadow testing' (also called dark launching) in microservices?
- Testing services only during off-peak hours
- Running new service code in parallel with production, mirroring real requests without affecting real responses (Correct answer)
- Testing services without logging to avoid performance impact
- Deploying to a separate environment that mirrors production data
Correct answer: Running new service code in parallel with production, mirroring real requests without affecting real responses
Shadow testing mirrors production traffic to a new service version silently — the new version processes requests but its responses are discarded, allowing behavior comparison without user impact.
Which type of test verifies that two microservices can communicate correctly according to a shared contract, without requiring both services to be running simultaneously?