๐Ÿ”ฐTechniques Used in Integration Testing

Types of Integration Testing

๐Ÿ’ฅ Big Bang Integration Testing

๐Ÿ’ก Idea: Integrate and test all modules together at one go in one big bang.

๐Ÿ“ฆ Process:

  • Take all modules/components and integrate them into the software build

  • Validate that all modules connect and function together as expected

  • Test interfaces between modules by performing end-to-end tests on the entire system

๐Ÿ‘ Use When:

  • The application is small or has few modules

  • Modules have low interdependency

  • Quick validation is needed with minimal debugging

โ—Considerations:

  • Difficult to isolate defects to a module

  • Not suitable for complex systems

  • Hard to test incrementally

๐Ÿ”ผ Top Down Integration Testing

๐Ÿ’ก Idea: Begin integration from top level modules and progressively add lower level modules

๐Ÿ“ฆ Process:

  • Start integrating from high level modules to low level modules

  • Test the functionality of top level modules first

  • Add lower level modules one by one and test integration

  • Follow the sequence of module dependencies top to bottom

๐Ÿ‘ Use When:

  • High level logic and structure needs to be tested first

  • Top modules are critical functionality

  • Low level modules can be tested more easily later

โ—Considerations:

  • Lower level defects may be missed initially

  • Stubs/drivers may be needed to test top level independent of low level

โฌ‡๏ธ Bottom Up Integration Testing

๐Ÿ’ก Idea: Begin integration from lowest level modules and progress upwards to higher level modules

๐Ÿ“ฆ Process:

  • Start integrating from low level modules to high level modules

  • Test the functionality of bottom modules first

  • Progressively add higher level modules on top and test integration

  • Follow the sequence of module dependencies bottom up

๐Ÿ‘ Use When:

  • Lower modules are reusable components

  • High level modules are dependent on low level interfaces

  • Critical low level components need to be tested first

โ—Considerations:

  • May not find defects in high level logic initially

  • Low level functionality may need stubs/drivers for initial testing

๐Ÿ’ผ Risk Based Integration Testing

๐Ÿ’ก Idea: Identify and test high risk modules and interfaces first based on priority

๐Ÿ“ฆ Process:

  • Analyze the modules and interfaces to identify high risk areas

  • Prioritize testing for modules that are complex, frequently used, mission critical etc.

  • Start integration testing from highest risk areas first

  • Progressively move to lower risk modules and interfaces

๐Ÿ‘ Use When:

  • Modules have varying levels of risk, complexity or usage

  • Testing priority needs to be given based on risk

  • Resources are limited and critical areas need focus first

โ—Considerations:

  • Dependent modules may still need testing for defects to be found

  • Understanding integration risks is important

๐Ÿ’ฝ Stub

๐Ÿ’ก Definition: A dummy module that simulates the intended behavior of an actual module

๐Ÿ“ฆ Usage:

  • Used when the actual module is unavailable or unfinished

  • Allows testing even if dependencies do not exist

  • Mimics how a real module would function

  • Helps isolate code under test from external dependencies

Example:

// Actual module
class PaymentGateway {
  chargeCreditCard(amount) {
    // charge credit card  
  }
}

// Stub module  
class PaymentGatewayStub {
  chargeCreditCard(amount) {
    return true; 
  }
}

// In test class
let gateway = new PaymentGatewayStub();
// Can test even if actual gateway unavailable

๐Ÿš˜ Driver

๐Ÿ’ก Definition: A module that invokes functionality of another module being tested

๐Ÿ“ฆ Usage:

  • Drives the code in another module by invoking it

  • Allows testing modules in isolation

  • Removes the need to rely on external sources of input

  • Often used along with stubs to test

Example:

// Driver
class UserInputDriver {

  simulateInput() {
    // Can send simulated input    
  }

}

// Class under test
class UserInput {
  
  getInput() {
    // Reads input from driver
  }
  
}

// In test class
let driver = new UserInputDriver();
let input = new UserInput();

// Drive input
driver.simulateInput(); 

๐ŸŽญ Mock Object

๐Ÿ’ก Definition: An object that simulates real objects to test interactions and outputs

๐Ÿ“ฆ Usage:

  • Used for testing by mimicking real dependencies

  • Allow control over test environment

  • Can inject behavior needed to exercise specific paths

  • Track interactions like method calls during test

Example:

// Mock object
let mockDB = MockDatabase();

// Class under test
class UserManager {
  constructor(db) {
    this.db = db;
  }
  
  getUser(userId) {
    return this.db.query("SELECT * FROM users WHERE id = " + userId);
  }
}  

// In test
let manager = new UserManager(mockDB);

// Test query interaction
manager.getUser(1);
assert(mockDB.verifyQueryCalled());

Last updated