Software EngineeringUnit 815 min read

Software Testing: Types, Techniques & Best Practices

Unit 8 of Software Engineering covers the fundamentals of software testing, including its types (unit, integration, system, acceptance), testing techniques (black-box, white-box, grey-box), test case design, and automation. It also explores test metrics, defect tracking, and the role of testing in quality assurance, wi

TAKEAWAYS:

  • Software testing is a verification and validation process to ensure software meets requirements and functions correctly, reducing defects before deployment.
  • Testing types are categorized by scope (unit, integration, system, acceptance) and technique (black-box, white-box, grey-box, exploratory).
  • Test case design involves identifying test inputs, expected outputs, and edge cases, often using equivalence partitioning or boundary value analysis.
  • Automated testing (e.g., Selenium, JUnit) improves efficiency, especially for regression testing, but requires careful script maintenance.
  • Defect tracking tools (e.g., Bugzilla, JIRA) help manage and prioritize issues during the software lifecycle.
  • Testing is not just a phase but an integral part of the Software Development Life Cycle (SDLC), influencing quality, cost, and user satisfaction.

1. Introduction to Software Testing

Software testing is the process of executing a program/system with the intent of finding errors. Its primary goals are:

  • Verification: Ensuring the software meets specified requirements.
  • Validation: Ensuring the software meets user needs and expectations.
  • Defect Detection: Identifying bugs, inconsistencies, or performance issues.
  • Quality Assurance: Ensuring reliability, usability, and security.

Why is Testing Important?

  • Cost-Effective: Fixing a bug early costs 100x less than fixing it post-deployment.
  • User Satisfaction: Reduces crashes, errors, and poor performance.
  • Compliance: Ensures adherence to standards (e.g., ISO, GDPR).
  • Risk Mitigation: Prevents financial and reputational losses.

Types of Software Testing

Testing can be classified based on when it is performed, what is tested, and how it is conducted.

1.1 Testing by Scope (When?)

Type Description Example
Unit Testing Tests individual components (functions, methods, classes) in isolation. Testing a calculateSalary() function in a payroll system.
Integration Testing Tests interactions between integrated units/modules. Testing how the UserAuth module interacts with the Database module.
System Testing Tests the entire system against functional and non-functional requirements. Testing an e-commerce app’s checkout process end-to-end.
Acceptance Testing Validates the system against user requirements (UAT: User Acceptance Testing). A bank testing a new ATM system before public release.

1.2 Testing by Technique (How?)

Type Description Example
Black-Box Testing Tests functionality without knowing internal code (focus on inputs/outputs). Testing a login button to see if it redirects to the dashboard.
White-Box Testing Tests internal logic (requires code knowledge). Checking if a loop in a sorting algorithm handles edge cases (e.g., empty array).
Grey-Box Testing Combines black-box and white-box (partial code knowledge). Testing API endpoints while knowing some backend logic.
Exploratory Testing Unscripted testing to find unexpected issues. Manually exploring a new app to find usability gaps.

2. Test Case Design

A test case is a set of inputs, execution conditions, and expected results designed to validate a specific feature.

Key Components of a Test Case

  1. Test ID: Unique identifier (e.g., TC_001).
  2. Description: What is being tested.
  3. Preconditions: Setup required (e.g., logged-in user).
  4. Test Steps: Actions to perform.
  5. Expected Result: What should happen.
  6. Actual Result: What actually happened (recorded after execution).
  7. Status: Pass/Fail/Blocked.

Test Case Design Techniques

Technique Description Example
Equivalence Partitioning Divides input data into partitions where each partition is expected to behave similarly. For age validation (0-120), test: <0, 0-18, 18-60, >60.
Boundary Value Analysis Tests boundary conditions (e.g., max/min values). Testing a form that allows only 50 characters: test with 0, 1, 49, 50, 51.
Decision Table Testing Tests combinations of inputs and conditions. A loan approval system with rules: income > 50k AND credit_score > 600.
State Transition Testing Tests system behavior across different states. Testing a traffic light system: Red → Green → Yellow → Red.

3. Real-World Applications of Software Testing

In the Real World

  1. eSewa (Nepal)

    • What it uses: Integration Testing and System Testing.
    • How? Before every update, eSewa’s payment gateway is tested for:
      • Seamless integration with banks (Nabil, Global IME).
      • Handling high transaction volumes (e.g., Dashain festival).
      • Security testing (preventing fraudulent transactions).
  2. Khalti (Nepal)

    • What it uses: Black-Box Testing (UI/UX) and Automated Regression Testing.
    • How? Khalti’s mobile app undergoes:
      • Manual testing for button clicks, OTP verification, and QR scans.
      • Automated scripts to ensure new features (e.g., split payments) don’t break existing ones.
  3. Daraz (Nepal/Global)

    • What it uses: Load Testing and Performance Testing.
    • How? During sales events (e.g., 11.11), Daraz tests:
      • Server response time under 10,000+ concurrent users.
      • Database performance when processing bulk orders.
  4. NTC (Nepal Telecom)

    • What it uses: System Testing and Security Testing.
    • How? Before deploying a new billing system:
      • Test call drops, SMS delivery, and internet speed across regions.
      • Penetration testing to prevent SIM-swapping attacks.
  5. Google (Global)

    • What it uses: White-Box Testing (Code Reviews) and A/B Testing.
    • How? Google’s search algorithm undergoes:
      • Unit tests for individual ranking functions.
      • A/B tests to compare two versions of a feature (e.g., new UI layout).

Worked Example: Testing a Bank Loan System

Scenario: A bank’s loan approval system must be tested before launch.

Test Case for Loan Eligibility

Test ID Description Precondition Test Steps Expected Result
TC_001 Loan approved for eligible user User has income > 50k and credit_score > 600 Enter details → Submit application Loan approved with terms displayed.
TC_002 Loan rejected for ineligible user User has income < 30k Enter details → Submit application Error: "Insufficient income. Try again."
TC_003 Boundary: Minimum income User has income = 30k Enter details → Submit application Loan rejected (strictly > 30k required).

Integration Test: Loan + Credit Check Module

  • Scenario: The loan system must communicate with the credit bureau.
  • Test Steps:
    1. Simulate a credit check request for a user with score = 650.
    2. Verify the loan system receives the response within 2 seconds.
    3. Check if the loan is approved based on the score.
  • Expected Result: Loan approved if credit score ≥ 600.

4. Software Testing Levels and Phases

Software testing is performed at multiple levels, each serving a unique purpose.

4.1 Levels of Testing

flowchart TD
    A["Unit Testing"] --> B["Integration Testing"]
    B --> C["System Testing"]
    C --> D["Acceptance Testing"]
    D --> E["Maintenance Testing"]

4.2 Testing in the Software Development Lifecycle (SDLC)

SDLC Phase Testing Activity
Requirements Review requirements for testability (e.g., ambiguous specs lead to unclear test cases).
Design Design test cases based on system architecture (e.g., UML diagrams).
Implementation Unit testing by developers (e.g., JUnit for Java, pytest for Python).
Testing Integration, system, and acceptance testing.
Deployment Smoke testing (basic functionality check) before release.
Maintenance Regression testing after bug fixes or updates.

5. Automated Testing

Automated testing uses scripts to execute tests, reducing human effort and improving efficiency.

Types of Automated Testing

Type Tools Use Case
Unit Testing JUnit, pytest, NUnit Testing individual functions (e.g., calculateTax()).
API Testing Postman, RestAssured Validating API responses (e.g., Daraz’s order status API).
UI Testing Selenium, Appium Automating web/mobile app interactions (e.g., Khalti’s login flow).
Performance Testing JMeter, LoadRunner Simulating 10,000 users on NTC’s website during peak hours.
Security Testing OWASP ZAP, Burp Suite Detecting SQL injection vulnerabilities in eSewa’s payment gateway.

Advantages of Automated Testing

  • Speed: Runs thousands of tests in hours.
  • Accuracy: Reduces human error in repetitive tasks.
  • Reusability: Scripts can be reused across projects.
  • Cost-Effective: Long-term savings on manual testing efforts.

Disadvantages

  • Initial Setup Cost: Writing and maintaining scripts takes time.
  • Not for Exploratory Testing: Requires predefined test cases.
  • False Positives/Negatives: Poorly written scripts may misreport results.

6. Defect Tracking and Management

Defects (bugs) must be tracked, prioritized, and resolved efficiently.

Defect Life Cycle

stateDiagram-v2
    [*] --> New: Defect reported
    New --> Assigned: Developer assigned
    Assigned --> Fixed: Bug fixed
    Fixed --> Retest: QA verifies fix
    Retest --> Reopened: If bug persists
    Reopened --> Fixed: Fix again
    Fixed --> Closed: Defect resolved
    Fixed --> Deferred: Postponed for later
    Closed --> [*]

Defect Tracking Tools

Tool Features
JIRA Issue tracking, sprint planning, Agile support.
Bugzilla Open-source, supports custom workflows.
Trello Kanban-style board for visual defect tracking.
MantisBT Web-based, good for small teams.

7. Non-Functional Testing

Non-functional testing evaluates system attributes other than functionality.

Type Description Example
Performance Testing Tests speed, scalability, and stability under load. Testing Pathao’s app during Diwali (high user load).
Security Testing Identifies vulnerabilities (e.g., data breaches). Penetration testing on Ncell’s customer portal.
Usability Testing Evaluates user-friendliness (e.g., UI/UX). Testing Daraz’s mobile app for elderly users.
Compatibility Testing Ensures software works across devices/OS. Testing eSewa on Android, iOS, and Windows.
Reliability Testing Measures system uptime and fault tolerance. Testing NTC’s network during monsoon (power outages).

8. Exam Tip

How This Unit is Examined

  1. Theory Questions (30-40%)

    • Define black-box vs. white-box testing.
    • Explain equivalence partitioning with an example.
    • Compare unit testing vs. integration testing.
  2. Scenario-Based Questions (30-40%)

    • Given a loan approval system, design 3 test cases using boundary value analysis.
    • Explain how automated testing would improve Khalti’s transaction processing.
    • Describe the defect life cycle with a real-world example (e.g., NTC app crash).
  3. Diagram-Based Questions (20-30%)

    • Draw the SDLC with testing phases.
    • Sketch a test case template for an e-commerce cart.
    • Illustrate a state transition diagram for a traffic light system.

Key Formulas to Remember

  • Test Coverage (%) = (Number of test cases passed / Total test cases) × 100
  • Defect Density = Total defects / Size of software (e.g., lines of code)

Common Mistakes to Avoid

  • Ignoring edge cases (e.g., empty input fields).
  • Not documenting test cases properly (leads to confusion).
  • Overlooking non-functional testing (performance/security are critical).
  • Assuming automation replaces manual testing (exploratory testing is still needed).

Final Checklist Before Exam

✅ Understand all testing types (unit, integration, system, acceptance). ✅ Know test case design techniques (equivalence partitioning, boundary value). ✅ Practice real-world examples (eSewa, Khalti, Daraz). ✅ Memorize defect life cycle and SDLC testing phases. ✅ Be ready to draw diagrams (test case template, state diagrams). ✅ Revise automated testing tools (Selenium, JUnit, Postman).


Based on the PU BE Computer (PU) syllabus for Software Engineering (CMP348), unit 8.

Discussion

Loading…