Software Engineering basics - Component Testing

Component Testing (also called Module Testing or Unit Testing)

Definition:
Component testing is the process of testing individual components or modules of a software system in isolation to verify that each one functions correctly according to its design and requirements.

It’s the lowest level of testing in the Software Testing Life Cycle (STLC) — performed before integration testing.


Purpose of Component Testing

  • To ensure that each independent unit (function, class, or module) works as intended.

  • To detect and fix defects early in the development process.

  • To validate the internal logic, data flow, and functionality of a single component.


Key Characteristics

  • Conducted after coding and before integrating modules.

  • Each component is tested in isolation, often using stubs or drivers to simulate inputs and outputs.

  • Typically performed by developers, but sometimes by testers in a controlled environment.


Example

Suppose you’re building an online shopping system.
Before testing the full application, you might test each component separately:

  • Login module – checks if user authentication works correctly.

  • Payment module – verifies that payment calculations and processing are accurate.

  • Cart module – ensures adding/removing products functions as expected.

Each of these modules is tested individually before integrating them together.


Techniques Used

  1. White-box testing techniques:

    • Focus on internal logic, code paths, and data flow.

    • Examples: statement coverage, branch coverage, condition coverage.

  2. Black-box testing techniques:

    • Focus on input-output behavior without looking at internal code.

    • Examples: boundary value analysis, equivalence partitioning.


Test Artifacts

  • Component Specification / Low-Level Design (LLD): Basis for creating test cases.

  • Test Cases and Test Data: Created for each module.

  • Stubs and Drivers:

    • Stub: Simulates a lower-level module that’s not yet developed.

    • Driver: Simulates a higher-level module that calls the component being tested.


Advantages

  • Detects defects early, reducing cost and effort of fixing them.

  • Ensures that each module is reliable before integration.

  • Simplifies debugging since issues are isolated within a single component.


Disadvantages

  • Does not test interactions between components (that happens in integration testing).

  • May require creating stubs/drivers, which adds extra work.


Example Scenario

Let’s say you have a function that calculates total price:

def calculate_total(price, quantity):
    return price * quantity

A component test might verify:

  • calculate_total(10, 5) returns 50

  • calculate_total(0, 10) returns 0

  • Negative or invalid inputs are handled properly

These checks confirm that this individual unit works correctly before combining it with other modules (like tax calculation or discounts).


In Summary

Aspect Description
Level Lowest level of testing
Focus Individual module or component
Performed By Developers (mostly)
Techniques Used White-box and black-box testing
Goal Verify correctness and stability of module
Tools (examples) JUnit, NUnit, PyTest, etc.