Strategies for Testing Large Systems
Integration Testing Strategies
Unit tests check each module on its own, but may miss disagreements about what passes between modules. Integration testing combines unit-tested modules and exercises their actual interactions, testing interfaces such as parameter order, units, data formats, error signals and the sequence of calls. It typically comes after unit testing and before system testing. The main planning decision is the order in which you combine the modules.
What integration testing looks for
An interface failure reflects a disagreement at a module boundary; the underlying defect may be in the caller's or the callee's implementation. Typical cases:
- A caller passes amounts in cents while the callee expects dollars.
- Two parameters of the same type are swapped.
- A callee signals failure with a null value that the caller never checks.
- A module calls another before the data it depends on has been initialised.
Each module can pass its own unit tests and still fail here, especially if those tests reflect different readings of the specification. Specification-based unit tests can detect incorrect interface assumptions. Integration testing complements them by exercising the actual calls and responses between real modules, exposing mismatches that isolated tests may miss.
Big-bang versus incremental integration
In big-bang integration you link every module at once and run the system. You write no scaffolding, but when a test fails every interface is a suspect, so locating the fault is slow. Incremental integration adds one module, or a small cluster, at a time and tests after each addition. Suppose a build that passed fails right after module X joins. Then X and the interfaces it just brought in are the most likely suspects.
Incremental integration needs placeholders for modules that are not yet present:
Placeholder | Stands in for | What it does |
|---|---|---|
Stub | A called module not yet integrated | Accepts the call and returns a fixed response taken from the specification |
Driver | A calling module not yet integrated | Sets up inputs, calls the modules under test and checks the results |
Top-down, bottom-up and sandwich orders
The call hierarchy gives three common incremental orders.
- Top-down: start with the main module. Replace stubs with real modules level by level (breadth-first) or branch by branch (depth-first). You need no drivers, because the main module is the entry point.
- Bottom-up: start with the leaf modules, which call nothing, and test them under drivers. Then replace each driver with the real calling module. You need no stubs, because every callee is real before its caller arrives.
- Sandwich: choose a middle target layer. Test the layers above it top-down with stubs and the layers below it bottom-up with drivers, then integrate the target layer.
Take a hierarchy of n modules, of which L are leaf modules. The scaffolding counts are
In top-down integration, every module except the main one is called at some point while it is still absent, so each needs a stub. In bottom-up integration, every calling module is simulated at some point, so each needs a driver. These counts assume a tree-shaped call hierarchy in which each module is integrated once.
Example: In the hierarchy in the figure, n=7 and the leaves are C, E, F and G, so L=4. Top-down integration needs 7−1=6 stubs and no drivers. Bottom-up integration needs 7−4=3 drivers, which simulate A, B and D, and no stubs. Now take a sandwich with B, C and D as the target layer. You test A against 3 stubs, for B, C and D. You test E, F and G under 2 drivers, for B and D. That makes 5 placeholders in total.
Strategy | Placeholders | Early strength | Main weakness |
|---|---|---|---|
Big-bang | None | No scaffolding to write | Faults are hard to localise |
Top-down | Stubs | Main control flow is visible early | Testing some low-level modules may be delayed, especially with breadth-first integration |
Bottom-up | Drivers | Low-level modules, often the riskiest, are exercised early | No end-to-end flow until the final step |
Sandwich | Both | Top and bottom layers progress in parallel | Target-layer interfaces are exercised last, from both sides at once |
Depth-first top-down integration can reach a leaf early by completing one branch before moving to another.
What to remember
- Integration testing exercises actual module interactions to expose interface faults that unit tests may miss.
- Incremental integration localises faults; big-bang integration avoids scaffolding but makes diagnosis slow.
- Stubs replace missing callees; drivers replace missing callers.
- For a tree of n modules with L leaves: top-down needs n−1 stubs, and bottom-up needs n−L drivers.
- Sandwich integration uses stubs above the target layer and drivers below it.
Example: Planning the integration of an order service
An online store's order service has ten unit-tested modules arranged in the call hierarchy below. Each line joins a calling module above to a module it calls below. Use the counting convention from the lesson: one stub for each called module that is absent, and one driver for each calling module that must be simulated.
a) How many stubs and how many drivers does top-down integration need?
In top-down integration OrderController is real from the start. Every other module is called before it is integrated, so each one needs a stub. The hierarchy has ________ modules, so
No drivers are needed, because OrderController is the entry point that the tests run through. Top-down integration needs 9 stubs and 0 drivers.
b) How many stubs and how many drivers does bottom-up integration need?
The leaf modules are PriceCalc, Inventory, CardGateway, FraudCheck, Receipt and RateQuote, so L = ________. A driver simulates each calling module: OrderController, Cart, Payment and Shipping.
No stubs are needed, because every callee is real before its caller is integrated. Bottom-up integration needs 4 drivers and 0 stubs.
c) Cart, Payment and Shipping form the target layer of a sandwich integration. How many placeholders does the plan need in total?
Above the target layer, OrderController is tested against stubs for Cart, Payment and Shipping, so the top part needs ________. Below the target layer, the six leaf modules are tested under drivers that simulate their callers. Those callers are Cart, Payment and Shipping, so the bottom part needs ________. The sandwich plan needs 3+3=6 placeholders, fewer than the 9 stubs of the pure top-down plan.
d) The team integrates top-down, breadth-first. Cart and Shipping have already replaced their stubs, and all tests pass. Payment then replaces its stub, and an order test fails. How many interfaces between real modules does this step newly exercise? Compare this with a big-bang build that fails.
The only new interface between real modules is the one from OrderController to Payment, because Payment's own calls go to ________ stubs for CardGateway, FraudCheck and Receipt. The first place to look is therefore that single interface, along with Payment's handling of the stub responses. If a stub's fixed values disagree with the specification, the stub itself can also cause the failure.
A big-bang build that fails leaves all n−1=9 interfaces of the tree as suspects. So the incremental step narrows the search to 1 new real interface instead of 9.
A team is choosing how to integrate a system whose unit-tested modules form a tree-shaped call hierarchy. Which of the following statements about integration orders are true? Select all that apply.
A library management system has twelve unit-tested modules. Every module except LibraryApp is called by exactly one other module, as listed below.
Module | Modules it calls |
|---|---|
LibraryApp | Catalog, Loans, Accounts |
Catalog | Search, Indexer |
Search | Tokenizer |
Loans | Checkout, Returns, Fines |
Fines | FeeCalc |
Accounts | Login |
Indexer | none |
Tokenizer | none |
Checkout | none |
Returns | none |
FeeCalc | none |
Login | none |
The team integrates bottom-up. It writes one driver for each calling module that must be simulated, and a single driver exercises all of that module's callees. How many drivers does the plan require? Give your answer as a whole number.