Back to Catalog
Microservices
Testing
Service Component Test
Test a service in isolation using test doubles for everything it calls.
Intent & Description
Real-world Use Case
Order Service component tests: start Order Service + real Postgres (Testcontainers) + WireMock for Restaurant Service and Payment Service. POST /orders → assert 201 Created + order row in DB. Runs in 30 seconds.
Source
📌 TL;DR
Service component tests = test your service in a box. Real DB, fake everything else. Fast, isolated, essential for CI.
Advantages
- Fast — no dependency service startup time
- Deterministic — no flakiness from real downstream services
- Tests the whole service slice (API + logic + DB)
- Runs in CI without a full environment
Disadvantages
- Test doubles can drift from real service behavior (use contract tests alongside)
- Doesn’t test real service-to-service integration
- Maintaining stubs as APIs evolve is effort
- May miss edge cases that only appear with real dependencies