Skip to content

Testing & QA

Integration Tests (Pieces Working Together)

The idea, in plain English

An integration test checks that two or more pieces of your code work correctly TOGETHER, not just alone. Each guitar string can be perfectly in tune on its own, but you only know the chord sounds right when you strum them together. Unit tests prove each part works; integration tests prove the parts connect properly — that the data one piece hands to the next is the shape the next one expects.

How it works

  1. 1Pick two or more real pieces that must cooperate, like a service and the store it saves to.
  2. 2Wire the actual pieces together — no faking the seam you're trying to test.
  3. 3Run an action that flows through all of them, from the first piece to the last.
  4. 4Assert on the end result AND on the state left behind, to confirm the handoff between pieces worked.

When you'd use it

Use integration tests where separate parts meet: code plus its database, one service calling another, a parser feeding a validator. They catch the bugs that live in the gaps between units, which unit tests can't see.

Common beginner mistakes

  • Faking the very connection you meant to test. If you stub out the store, you're back to a unit test and you never checked the real handoff.
  • Testing everything only through slow, wide integration tests. They're valuable but slower — keep a big base of fast unit tests and use integration tests for the seams.

Try it — edit and run

Click the code to edit · press ⌘/Ctrl+↵ to run

Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.

Expected output — hit Run to try it
registered Ada
Store now has: Ada (active: yes)
PASS: pieces work together

Not sure this is the right topic? See the learning paths → or where this leads →