# Service Component Test

> Test a service in isolation using test doubles for everything it calls.

- **Category**: Microservices
- **Subcategory**: Testing
- **Canonical URL**: https://designpattern.fyi/patterns/service_component_test/

---

## Description
Clean, reusable architecture pattern.


## Use Cases
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.





## Trade-offs


### 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




### Considerations & Drawbacks

- 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







---
**Reference**: [Original Source](https://microservices.io/patterns/testing/service-component-test.html)

