Microservices Testing Strategies for Microservices 2 — Questions and Answers
Question 1: Which type of test is most effective for detecting issues that only appear when multiple microservices interact together in a realistic environment?
- Unit tests
- Contract tests
- End-to-end tests (Correct answer)
- Property-based tests
Correct answer: End-to-end tests
End-to-end tests exercise the full system across multiple services, catching integration issues that unit and contract tests cannot reveal since they only emerge from real service interactions.
Question 2: What is the main drawback of relying heavily on end-to-end tests in a microservices architecture?
- They cannot find bugs that unit tests miss
- They are slow, brittle, and difficult to maintain as the number of services grows (Correct answer)
- They require contract files to be shared between teams
- They cannot be automated and require manual execution
Correct answer: They are slow, brittle, and difficult to maintain as the number of services grows
End-to-end tests in microservices are notoriously slow and flaky because they depend on the availability and correct behavior of many services simultaneously, making them expensive to maintain.
Question 3: What does 'consumer-driven contract testing' mean?
- The service provider defines the contract and consumers must adapt to it
- The consumer defines the expected interactions, and the provider verifies it can fulfill them (Correct answer)
- An external team writes contracts for all services
- Contracts are auto-generated from OpenAPI specs
Correct answer: The consumer defines the expected interactions, and the provider verifies it can fulfill them
In consumer-driven contract testing, the consumer records the interactions it expects, and the provider's test suite verifies it satisfies all consumer contracts, giving consumers control over the interface.
Question 4: In microservices testing, what is a 'stub'?
- A real service deployed in a test environment
- A lightweight replacement that returns predefined responses without complex logic (Correct answer)
- A tool that records and replays HTTP interactions
- A performance benchmark baseline
Correct answer: A lightweight replacement that returns predefined responses without complex logic
A stub is a simple test double that returns hardcoded or predefined responses to specific inputs, allowing the service under test to behave as if a real dependency responded.
Question 5: Which tool is commonly used to record and replay HTTP interactions between microservices for testing purposes?
- WireMock (Correct answer)
- JUnit
- Prometheus
- Kafka
Correct answer: WireMock
WireMock is a popular HTTP mock server that can record real service interactions and replay them during tests, enabling isolated testing without live dependencies.
Question 6: What is 'mutation testing' and why is it used in microservices development?
- Testing how services handle schema changes between versions
- Automatically introducing small code changes to verify that existing tests detect them (Correct answer)
- Testing how microservices adapt when dependencies change their APIs
- Generating tests by mutating existing test cases
Correct answer: Automatically introducing small code changes to verify that existing tests detect them
Mutation testing introduces deliberate small bugs (mutations) into code and checks whether the test suite catches them, measuring test suite effectiveness rather than just code coverage.
Question 7: What is the purpose of a 'smoke test' in a microservices deployment pipeline?
- Test service performance under heavy load
- Run a minimal set of critical tests immediately after deployment to verify basic functionality (Correct answer)
- Detect memory leaks in services over time
- Validate all edge cases and error paths
Correct answer: Run a minimal set of critical tests immediately after deployment to verify basic functionality
Smoke tests are a small, fast subset of tests run right after deployment to verify the service started correctly and core functionality works before running the full test suite.
Which type of test is most effective for detecting issues that only appear when multiple microservices interact together in a realistic environment?