← Back to libraryQuestion 245 of 273
📋Software TestingIntermediate

Types of Testing - Unit, Integration, System

📌 Definition:

Three main levels of testing based on scope: testing individual components, multiple components together, or the entire system.

📖 Detailed Explanation:

Think of building a car: Unit = test individual components (engine, wheels, battery). Integration = test engine+gearbox working together. System = test entire car. Each level requires different tools, expertise, and effort. The testing pyramid suggests doing lots of unit tests (cheap), fewer integration tests, and least system tests (expensive).

📎 Unit Testing:
Definition:

Testing individual functions or methods in isolation to verify they work correctly

Scope:

Single component/function/method

Who Does It:

Developers (not QA)

When Done:

During development - Developers write and run unit tests continuously

Tools:
  • JUnit (Java)
  • TestNG (Java)
  • Pytest (Python)
  • Mocha (JavaScript)
Example:
Scenario:

Test a login() function

Test Cases:
  • Valid email + valid password → returns success
  • Valid email + invalid password → returns error
  • Invalid email format → returns error
  • Empty fields → returns error
Advantages:
  • Catches bugs early during development
  • Fixes are cheap - developer is still working on that code
  • Promotes better code design
  • Quick feedback (milliseconds)
  • Easy to automate and maintain
Disadvantages:
  • Tests isolated functions, not real workflows
  • Doesn't catch integration bugs
  • Developer might test their own code bias (miss edge cases)
📎 Integration Testing:
Definition:

Testing how multiple components/modules work together when integrated

Scope:

Multiple components/modules/services

Who Does It:

QA engineers + developers

When Done:

After components are individually tested but before full system testing

Tools:
  • Postman (API)
  • Rest Assured (Java)
  • SoapUI
  • pytest-cov
Example:
Scenario:

Test user registration workflow

Components Involved:
  • Registration form (Frontend)
  • API endpoints (Backend)
  • Database (Data storage)
  • Email service (Notifications)
Test Flow:

1) User fills registration form. 2) Frontend sends data to API. 3) API validates and stores in database. 4) Email service sends confirmation. 5) User receives email and confirms.

Real World Issue:

Unit test passed: Email sending function works. Integration test failed: Email not sent because API doesn't call email service. Unit tests are too isolated!

Advantages:
  • Catches real-world interface bugs
  • Tests data flow between components
  • Finds missing integrations
  • Closer to real-world usage than unit tests
Disadvantages:
  • More complex to set up (multiple components)
  • Slower execution than unit tests
  • Requires mock data and services
📎 System Testing:
Definition:

Testing complete system end-to-end against all requirements

Scope:

Entire application including all features, databases, external integrations

Who Does It:

QA engineers

When Done:

After all development is complete, before UAT

Tools:
  • Selenium (Web)
  • Cypress
  • Appium (Mobile)
  • LoadRunner (Performance)
Example:
Scenario:

E-commerce system end-to-end

Test Flow:
  • User logs in
  • Browses products
  • Adds items to cart
  • Applies discount code
  • Proceeds to checkout
  • Enters shipping address
  • Selects payment method
  • Completes payment
  • Receives order confirmation
  • Gets email with tracking number
  • Admin sees order in dashboard
Advantages:
  • Tests complete user journey
  • Verifies all requirements are met
  • Catches end-to-end bugs
  • Most realistic testing scenario
Disadvantages:
  • Most expensive and time-consuming
  • Hardest to debug (if fails, unclear which component caused it)
  • Requires fully functional environment
  • Slowest execution (minutes per test)
📎 Testing Pyramid Visual:
Description:

Cost and benefit of testing levels

Structure:
  • Top (Pyramid tip): 1 System Test - Covers all features end-to-end, expensive, slowest
  • Middle: 10 Integration Tests - Multiple components, medium cost, medium speed
  • Base: 100 Unit Tests - Single functions, cheap, fastest
Principle:

Write many unit tests (cheap, fast, broad coverage), fewer integration tests (moderate), and least system tests (expensive, slow, narrow coverage)

📎 Sequence In Project:

Unit → Integration → System → User Acceptance Testing (UAT)

🎯 Scenario-Based Interview Question:

A critical bug is found in production where users can see other users' data. You trace it to database query that joins orders and payments tables. This works in unit tests but fails in integration. Why?

💡 Quick Tip:

🔺 Testing pyramid: Most unit tests (cheap), fewer integration, least system tests. Write many, test fast, fail early.

💡 Interview Focus:

Interviewers test your understanding of why all three levels are necessary and how they complement each other.