Test stages: what to test, and where in the pipeline
Unit, integration, end-to-end, performance and security tests, how many of each, and which stage runs them.
Tests trade speed for realism. Unit tests check small pieces in milliseconds and should make up most of your tests. Integration tests check your code against real dependencies (a database, a queue) started in the pipeline. End-to-end tests drive the whole app like a user and are slow and fragile, so keep a few for the most important journeys.
Put them in stages: unit tests and lint on every push, integration tests on every pull request, end-to-end and performance tests after deployment to a test environment, and smoke tests after every production deployment. Security tests sit alongside: dependency and secret scanning on pull requests, image scanning after the build.
Treat test results as data: publish them so failures are readable, track coverage without worshipping it, and quarantine flaky tests quickly rather than letting them teach people to ignore red builds.
Cost. Free to practise; service containers and runners in public repositories cost nothing.
Use it when
- you're deciding which tests to run where.
- the pipeline is slow because every test runs everywhere.
- bugs reach staging that tests should have caught.
How it works
- Unit
- Fast, many, every push.
- Integration
- Real dependencies in service containers, every pull request.
- End-to-end
- A few key journeys, after deploying to test.
- Performance
- Load tests before big releases or on a schedule.
- Smoke
- A quick is-it-alive check after every deployment.
Options
- Service containers
- Databases and queues beside the job; simple and free.
- Testcontainers
- Tests start their own containers from code.
- A shared test environment
- Closest to production; slower and can be busy.
Example. Brindle Outdoor ran 40 minutes of browser tests on every push. They moved most checks to unit and API tests, kept six browser journeys after deployment to test, and pull request results arrived in seven minutes.
Don't confuse it with
- Integration test
- Your code with a real dependency.
- End-to-end test
- The whole system, through the user interface or public API.
Words to know
- Test pyramid
- Many unit tests, fewer integration tests, very few end-to-end tests.
- Smoke test
- A quick check that a deployment works at all.
- Quarantine
- Taking a flaky test out of the blocking set while it's fixed.
Where to look
- Actions tab
- Test results
Practise it
- Run integration tests against a real databaseHow-to, Free
- Load test with Azure Load TestingHow-to, Costs money
- Deploy to Kubernetes and roll back on failureHow-to, Free
Read it in the guide, next to the tasks and labs.
Open in DevOps, Hands On