Integration Testing
What is Integration Testing?
Integration testing verifies that individual modules or units work correctly together when combined, focusing on the interfaces and data flow between them.
Common Approaches
- Big Bang Integration: All modules are combined at once and tested together.
- Top-Down Integration: Testing starts from top-level modules, using stubs for lower-level modules not yet developed.
- Bottom-Up Integration: Testing starts from lower-level modules, using drivers to simulate higher-level modules.
- Sandwich/Hybrid Integration: Combines both top-down and bottom-up approaches.
Why It Matters
Even if individual units pass their own tests, problems in how they communicate — mismatched data formats, incorrect API calls, timing issues — can only be caught once modules are integrated.
Planning Integration Tests Step by Step
- Map the interfaces. List every point where modules talk: function calls, REST APIs, message queues, shared database tables and files.
- Pick an approach and an order. Decide whether to go top-down, bottom-up or hybrid, and which pairs of modules to join first. Critical or risky interfaces usually go early.
- Identify missing pieces. Where a module is not ready, plan a stub or a driver to stand in for it.
- Write test cases per interface. Cover valid data, invalid data, empty responses, timeouts and errors coming back from the other side.
- Prepare shared test data that both modules agree on, such as a known customer and product.
- Execute, log and retest. When a defect is fixed, rerun the interface tests and a regression set around it.
Stubs and Drivers in Practice
A stub replaces a lower module that is called by the module under test. A driver replaces a higher module that calls it. Picture an order service that calls a payment gateway not yet available for testing. A stub with predictable answers lets the team test the integration logic now.
class PaymentGatewayStub:
def charge(self, amount, card_token):
if amount <= 0:
return {"status": "FAILED", "reason": "invalid amount"}
if card_token == "tok_declined":
return {"status": "DECLINED"}
return {"status": "SUCCESS", "txn_id": "TEST123"}
def test_order_is_paid_when_charge_succeeds():
service = OrderService(payment_gateway=PaymentGatewayStub())
order = service.place_order(item_id=7, amount=499, card_token="tok_ok")
assert order.status == "PAID"
assert order.txn_id == "TEST123"
def test_order_stays_pending_when_card_declined():
service = OrderService(payment_gateway=PaymentGatewayStub())
order = service.place_order(item_id=7, amount=499, card_token="tok_declined")
assert order.status == "PAYMENT_FAILED"
Once the real gateway sandbox is ready, the same tests run against it to confirm the actual contract matches what the stub assumed.
What to Check at Each Interface
| Interface | Typical checks |
|---|---|
| UI to API | Form fields map to the right request fields, errors from the API are shown clearly |
| Service to service | Field names, data types, date and currency formats, behaviour on timeouts |
| Service to database | Records saved with correct values, transactions roll back on failure |
| Message queue | Messages published once, consumer handles duplicates and bad messages |
| File exchange | File naming, encoding, header rows, partial files |
Component and system integration
Component integration testing joins modules inside one application. System integration testing joins your application with external systems such as a bank, an SMS provider or a partner's API, where you control only one side.
Mistakes That Weaken Integration Testing
- Mocking every dependency, so the tests become unit tests and real mismatches slip through.
- Testing only success responses, while real failures come from timeouts, retries and unexpected error bodies.
- Skipping integration because each team's unit tests pass, then finding format mismatches late.
- Sharing one database between test runs without cleanup, causing random failures.
Quick checklist: interface list complete, stubs documented, negative cases included, test data agreed, and real-system runs scheduled once dependencies are available.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.