Course contentsShow
← Software Engineering
Lesson 529 of 1,93316. Integration TestingFree lesson

Balancing Test Scope

Deciding which boundaries need integration tests, how much to test at each layer, and avoiding redundancy with unit tests.

Balancing Test Scope

You'll learn: How to decide which module boundaries need integration tests and how much to test at each layer without duplicating effort.

Integration tests sit between unit tests and end-to-end tests, verifying that modules work together correctly. But how do you decide what to test at the integration level versus leaving it to unit tests?

The Coverage Overlap Problem

Imagine you've already written unit tests that verify PaymentProcessor calculates the correct amounts. Now you're writing integration tests for OrderService calling PaymentProcessor. Should you test all the payment calculation scenarios again? That's redundant—you'd be testing the same logic twice.

Instead, integration tests should focus on the boundary behavior: Does OrderService call PaymentProcessor with the right data? Does it handle the responses correctly? Does error propagation work?

Deciding What to Test Where

Unit tests verify the internal logic of each module thoroughly. Test edge cases, calculations, business rules, and error conditions here.

Integration tests verify the connection points:

  • Data transformation across boundaries
  • Configuration and wiring between modules
  • Error propagation and handling
  • Communication protocols and contracts

If your unit tests already verify that PaymentProcessor rejects negative amounts, your integration test doesn't need to re-verify that logic. It just needs to verify that when PaymentProcessor throws that error, OrderService handles it appropriately.

The Balance

Think of unit tests as testing what each module does. Integration tests verify how modules work together. Avoid testing the "what" again at the integration level—focus on the handshake, not re-running the conversation both sides already had in their unit tests.

Key Takeaway: Integration tests should focus on boundary behavior and cross-module communication, not re-test logic already covered by unit tests—test the connections, not the components again.