Difference between unit and integration tests and CI pipeline placement

Grasp of the testing pyramid and CI gating.
Unit tests isolate code and run fast in the build stage; integration tests verify real wiring later. Target 70 percent unit tests.
Claiming both run together or cost the same.
WHAT THIS TESTS: This question probes whether you understand the testing pyramid as a cost and speed model, not just a buzzword. Interviewers want to see that you gate CI stages appropriately and know why unit tests belong early while integration tests come later.
A GOOD ANSWER COVERS: Four things in order. First, define unit tests as fast, isolated checks on functions or classes with mocked dependencies, usually running in milliseconds. Second, define integration tests as validations of real component interactions, often requiring databases, message queues, or external APIs, making them slower and more expensive. Third, place unit tests in the build stage right after compilation alongside static analysis and secrets detection, because they are cheap and should block immediate feedback. Fourth, place integration tests in a subsequent stage that uses a provisioned environment, because they need real infrastructure and should not slow down the tight developer feedback loop. Mention the 70 percent rule of thumb for unit test coverage.
COMMON WRONG ANSWERS: Saying unit and integration tests are just about scope without mentioning speed or infrastructure cost. Claiming integration tests run in the build stage on every commit without noting the environment requirement. Conflating unit tests with integration tests by saying unit tests hit a real database. Suggesting a 50-50 split instead of a pyramid shape. Ignoring that unit tests should have near-complete code coverage while integration tests cover critical paths.
LIKELY FOLLOW-UPS: How do you handle flaky integration tests in CI? When would you run contract tests versus integration tests? How do you parallelize integration tests without ballooning cloud costs? What is your strategy for testing microservices that depend on third-party APIs?
ONE CONCRETE EXAMPLE: In a typical AWS CodePipeline, the build stage compiles code and runs unit tests, SAST, and SCA. If coverage is below threshold or a unit test fails, the pipeline stops before any infrastructure is provisioned. Integration tests run in a staging stage using AWS CloudFormation or Terraform to spin up a temporary environment with an RDS instance and an API gateway. Only after integration tests pass does the pipeline proceed to performance or UI tests.
Source: docs.aws.amazon.com
Read the original → docs.aws.amazon.com
- #ci/cd
- #testing
- #unit-tests
- #integration-tests
- #pipeline
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.