Skip to content
tezvyn:

Difference between unit and integration tests and CI pipeline placement

Source: docs.aws.amazon.comEasyHow cards are made

Difference between unit and integration tests and CI pipeline placement
Summary

Grasp of the testing pyramid and CI gating.

Key points

Unit tests isolate code and run fast in the build stage; integration tests verify real wiring later. Target 70 percent unit tests.

Watch out for

Claiming both run together or cost the same.

What's really being asked

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.

The full answer

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.

The mistakes people make

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.

What usually comes next

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?

A 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.

Interview question

Why are unit tests placed in the build stage and integration tests in a later CI stage?

  • a.Unit tests need real databases and message queues to validate wiring
  • b.Unit tests are fast and isolated, while integration tests require real infrastructure and are slowerCorrect
  • c.Both test types have similar speed and infrastructure cost, so stage placement is arbitrary
  • d.Integration tests check isolated functions with mocked dependencies and belong in the build stage
Why?

Unit tests are fast and isolated with mocks, making them ideal for the build stage, while integration tests verify real wiring and need provisioned infrastructure, so they run later. Distractor B swaps the two definitions, which is a common misconception when candidates only memorize names without understanding the speed and isolation differences.

Just read this? Test yourself on what you have been reading.

Read the original → docs.aws.amazon.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on ci/cd — each one lists the topics its interview covers.

See open roles