How do unit tests fit into a CI pipeline?
Answer
Unit tests are the first and most important automated tests in a CI pipeline. They verify that individual functions or classes behave correctly in isolation, with all external dependencies (databases, APIs) mocked. Because they are fast (milliseconds per test), a suite of thousands of unit tests can complete in under a minute. In the CI pipeline, unit tests run immediately after the build step, before any deployment. A failing unit test fails the pipeline and blocks merging, giving developers near-instant feedback. Best practice is to enforce a code coverage threshold (e.g., 80% branch coverage) as a pipeline gate — if coverage drops below the threshold, the build fails. Fast unit tests are the foundation of a reliable CI pipeline; slow tests destroy developer experience by making every pipeline run take 30+ minutes.
Previous
What are git branching strategies for CI and how do GitFlow and trunk-based development compare?
Next
What is artifact storage in CI/CD and why is it important?