Test strategy and the test portfolio
A test strategy says what kinds of tests a system needs, at which boundaries, and who owns them. It’s an architecture decision, because the right mix depends on the system’s shape. A modular monolith and a set of thirty microservices need very different strategies, even if their features are identical.
The goal isn’t maximum coverage. It’s fast, trustworthy feedback: every change should be proven safe quickly enough that people keep running the tests, and the tests should fail only when something is really wrong.
Diagram
Section titled “Diagram”- Unit and component tests run the orders service alone, with dependencies replaced by test doubles. Fast, and most of the suite.
- Contract tests check that orders and payments still agree on their API, without deploying both together.
- Integration tests check the service against real infrastructure, such as its own database in a container.
- A small number of end-to-end tests run the most important user journeys across the whole system.
The test portfolio
Section titled “The test portfolio”| Test type | Scope | Speed | Catches | Typically owned by |
|---|---|---|---|---|
| Unit | One function or class | Milliseconds | Logic errors | Developers |
| Component (service) | One service, dependencies faked | Seconds | Behavior of the service through its API | The service team |
| Contract | The agreement between a consumer and a provider | Seconds | Breaking API or message changes | Both teams, checked in each pipeline |
| Integration | A service with real infrastructure (database, broker) | Seconds to minutes | Queries, mappings, configuration, transactions | The service team |
| End-to-end | Several services through the UI or API | Minutes | Wiring and critical journeys | Shared, kept small |
| Non-functional | Performance, security, accessibility, resilience | Minutes to hours | Quality attribute failures | Test architects with specialists |
| In production | The live system | Continuous | What only real traffic reveals | Product and operations teams |
How it works
Section titled “How it works”- Shape follows architecture. The classic test pyramid (many unit tests, fewer integration tests, very few UI tests) suits a monolith. For microservices, many teams prefer a “honeycomb” with most tests at the service level and few pure unit tests, because the risk lives in integrations. Use the shape that matches where your failures come from.
- Test at the boundaries the architecture defines. Each service’s public API is a natural test boundary. Tests that reach inside another team’s service are fragile.
- Contract tests replace most end-to-end tests between services. With consumer-driven contracts (for example, using Pact), each consumer publishes the requests it relies on, and the provider’s pipeline verifies them. A breaking change fails the provider’s build, before deployment.
- Keep end-to-end tests few and critical: sign-up, checkout, payment, the journeys that would make the news if broken. Every extra one adds minutes and flakiness.
- Test quality attributes explicitly. Each quality attribute scenario should map to a test: a load test, a failover drill, a security scan, an accessibility check.
- Shift right as well as left. Feature flags, canary releases, synthetic monitoring and observability test in production safely. Some failures only appear with real data and traffic.
- Treat flaky tests as defects. A test that fails randomly teaches people to ignore failures. Quarantine it and fix or delete it.
- Make risk visible. State what is not tested and why, so the decision is conscious.
- Fast feedback: most problems are found in seconds or minutes, by the team that caused them.
- Independent releases: contract tests let teams deploy without coordinated test cycles.
- Confidence in quality attributes, not just features.
- Needs developer ownership; a separate QA team can’t write unit, component and contract tests for everyone.
- Contract testing needs discipline and a shared broker or repository for contracts.
- Test doubles can drift from the real thing if contracts aren’t verified.
When to use it
Section titled “When to use it”Write an explicit test strategy for every significant system, and revisit it when the architecture changes, for example when splitting a monolith or adding asynchronous messaging.
When to avoid it
Section titled “When to avoid it”Don’t write a heavy, generic strategy document for a small internal tool. A short page answering “what do we test, where, and who owns it?” is enough.
Common pitfalls
Section titled “Common pitfalls”- The ice-cream cone: mostly manual and UI tests, few fast tests underneath. Slow, flaky and expensive.
- A shared end-to-end environment as the only quality gate, so every team waits on every other team.
- Mocking what you don’t own without contract tests, so the mocks lie.
- Coverage targets as the goal, rewarding tests that execute code without checking anything.
- No test owner for non-functional requirements until a performance problem reaches production.
Related pages
Section titled “Related pages”- See it applied: Example Lending, a full test strategy for one platform
- Test environments and test data
- Performance engineering
- Quality attributes and NFRs
- Microservices
- Event-driven architecture
Further reading
Section titled “Further reading”- Martin Fowler, The practical test pyramid (opens in a new tab) (by Ham Vocke)
- Martin Fowler, Testing strategies in a microservice architecture (opens in a new tab) (by Toby Clemson)
- Pact: consumer-driven contract testing (opens in a new tab)
- Google, Software Engineering at Google, chapter 11: Testing overview (opens in a new tab)
Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.