Table of Contents

    Testing Basics

    Programming Mastery

    Testing Basics

    Learn how software testing helps developers verify correctness, detect bugs, improve quality, and deliver reliable applications.

    Introduction

    Testing is the process of checking whether a program works correctly and meets the expected requirements.

    Writing code is not enough. Developers must also verify that the code behaves correctly for normal inputs, wrong inputs, edge cases, and real-world usage.

    Testing helps developers find problems before users find them.

    Good testing improves software quality, reduces bugs, increases confidence, and makes future changes safer.

    Easy Real-Life Example

    Testing as Checking a Car Before Driving

    Before a car is used on the road, important parts such as brakes, lights, tyres, engine, and steering should be checked. This prevents accidents and gives confidence to the driver.

    Car Check:
    Check brakes
    Check lights
    Check tyres
    Check fuel
    Check steering
    
    Software Testing:
    Check input
    Check output
    Check calculations
    Check errors
    Check user flow

    Testing software is similar. Before releasing a program, we check whether it works safely and correctly.

    What is Software Testing?

    Software testing is the activity of evaluating a software application to check whether it works as expected.

    Testing compares the actual result produced by the program with the expected result.

    Key Idea: Testing verifies whether the software behaves correctly according to requirements.

    Simple Testing Example

    Requirement:
    If marks are 40 or above, result should be Pass.
    
    Input:
    marks = 45
    
    Expected Output:
    Pass
    
    Actual Output:
    Pass
    
    Test Result:
    Passed

    If the actual output matches the expected output, the test passes. If not, the test fails.

    Why Testing is Important

    Testing is important because even small mistakes in software can create serious problems.

    A small bug may cause wrong calculations, failed payments, security issues, data loss, poor user experience, or application crashes.

    Benefits of Testing

    • Finds bugs before release.
    • Improves software quality.
    • Checks whether requirements are met.
    • Reduces user complaints.
    • Makes future changes safer.
    • Helps developers debug faster.
    • Improves confidence in the application.
    • Supports better teamwork between developers and testers.
    • Reduces cost of fixing defects later.
    • Improves reliability and maintainability.

    Common Terms in Testing

    Students should understand some basic testing terms before learning testing deeply.

    Term Meaning Simple Example
    Bug A problem in software that causes incorrect behavior. Login fails even with correct password.
    Defect A flaw found in software during testing. Wrong total is shown on invoice.
    Test Case A set of inputs, steps, and expected result. Check login with valid credentials.
    Expected Result The result that should happen. System should show “Login successful”.
    Actual Result The result that actually happens. System shows “Invalid user”.
    Test Data Input values used for testing. Email, password, marks, price.
    Test Suite A collection of related test cases. All login-related test cases.

    Levels of Testing

    Software testing can happen at different levels. Each level checks a different part of the software.

    Testing Level What It Tests Example
    Unit Testing Individual function, method, or component. Test grade calculation function.
    Integration Testing How different modules work together. Login module works with user database.
    System Testing The complete application as a whole. Test full Student Management System.
    Acceptance Testing Whether users accept the system. Teacher verifies report card feature.

    Unit Testing

    Unit testing checks a small unit of code, such as a function or method.

    It is usually performed early and helps developers find bugs before different parts of the system are combined.

    Example: Unit Test Idea

    Function:
    isPassingMark(marks)
    
    Requirement:
    Return true if marks are 40 or above.
    
    Test Cases:
    marks = 50  → expected true
    marks = 40  → expected true
    marks = 39  → expected false
    marks = 0   → expected false

    Unit testing checks whether a small piece of logic works correctly.

    Integration Testing

    Integration testing checks whether different modules work correctly together.

    Sometimes individual modules work correctly, but problems appear when they communicate with each other.

    Example:
    Login Form Module
            ↓
    Authentication Module
            ↓
    User Database
    
    Integration Test:
    Check whether login form sends data correctly,
    authentication checks credentials,
    and database returns matching user information.

    Integration testing helps find communication and data-flow problems between modules.

    System Testing

    System testing checks the complete software system.

    It verifies whether the full application works according to requirements.

    Student Management System Testing:
    - Add student
    - Update marks
    - Search student
    - Generate report
    - Login and logout
    - Validate permissions

    System testing checks the application from an overall user and business perspective.

    Acceptance Testing

    Acceptance testing checks whether the software satisfies user or business expectations.

    It is often performed by business users, clients, teachers, administrators, or product owners.

    Acceptance Test Example:
    A teacher checks whether the Student Management System can:
    - Add students
    - Enter marks
    - Calculate grades
    - Generate report cards
    
    If the teacher accepts the behavior,
    the feature may be considered ready.

    Regression Testing

    Regression testing checks whether existing features still work after code changes.

    When developers fix bugs or add new features, they must ensure old functionality is not broken.

    Example:
    A new discount feature is added to an e-commerce app.
    
    Regression testing checks:
    - Login still works
    - Cart still works
    - Payment still works
    - Invoice still works
    - Old discount rules still work

    Regression testing protects existing features from accidental breakage.

    Manual Testing vs Automation Testing

    Testing can be done manually by humans or automatically using tools and scripts.

    Manual Testing Automation Testing
    Tester performs test steps manually. Test scripts execute steps automatically.
    Useful for exploratory and visual checks. Useful for repeated tests.
    Can be slower for repeated tasks. Can be faster for repeated test execution.
    Human judgment is involved. Tool follows predefined instructions.

    What is a Test Case?

    A test case is a documented set of steps used to verify a specific feature or behavior.

    A good test case clearly explains what to test, what data to use, what steps to follow, and what result is expected.

    Test Case Structure

    Field Meaning
    Test Case ID Unique identifier for the test case.
    Test Scenario Feature or situation being tested.
    Precondition Condition required before testing starts.
    Test Steps Actions performed during testing.
    Test Data Input values used during testing.
    Expected Result Result that should happen.
    Actual Result Result that actually happened.
    Status Pass or Fail.

    Example Test Case: Login

    Field Details
    Test Case ID TC_LOGIN_001
    Scenario Login with valid username and password.
    Precondition User account already exists.
    Test Data Valid email and valid password.
    Steps Open login page, enter credentials, click login.
    Expected Result User should be redirected to dashboard.
    Status Pass or Fail after execution.

    Positive and Negative Testing

    Testing should include both correct and incorrect situations.

    Testing Type Meaning Example
    Positive Testing Checks expected valid behavior. Login with correct email and password.
    Negative Testing Checks how system handles invalid input. Login with wrong password.

    Boundary Testing

    Boundary testing checks values at the edge of allowed ranges.

    Many bugs happen near minimum and maximum limits.

    Requirement:
    Marks must be between 0 and 100.
    
    Boundary Test Values:
    -1   → invalid
    0    → valid
    1    → valid
    99   → valid
    100  → valid
    101  → invalid

    Boundary testing is useful for marks, age, quantity, price, password length, and date ranges.

    Edge Cases

    An edge case is an unusual or extreme situation that may still happen.

    Example Feature:
    Calculate average marks.
    
    Normal Case:
    [80, 70, 90]
    
    Edge Cases:
    Empty marks list
    Marks with zero
    Marks above 100
    Negative marks
    Only one subject
    Very large number of subjects

    Testing edge cases helps make software more reliable.

    Smoke Testing

    Smoke testing is a quick basic test to check whether the main features of an application are working.

    Smoke Test Example:
    - Application opens
    - Login page loads
    - User can login
    - Dashboard opens
    - Logout works

    If smoke testing fails, deeper testing may not be useful until the main issue is fixed.

    Debugging and Testing

    Testing finds problems. Debugging helps identify and fix the cause of those problems.

    Testing Debugging
    Checks whether software works correctly. Finds why software is not working correctly.
    Can be done by tester or developer. Usually done by developer.
    Finds defects. Fixes defects.

    Student-Friendly Example: Grade Calculator Testing

    Feature:
    Grade Calculator
    
    Requirement:
    - 90 and above: A
    - 75 to 89: B
    - 60 to 74: C
    - 40 to 59: D
    - Below 40: Fail
    - Marks must be 0 to 100
    
    Test Cases:
    marks = 95  → Grade A
    marks = 75  → Grade B
    marks = 60  → Grade C
    marks = 40  → Grade D
    marks = 39  → Fail
    marks = -5  → Invalid marks
    marks = 101 → Invalid marks

    These test cases check normal values, boundary values, and invalid values.

    Real-World Example: E-Commerce Checkout Testing

    Test Area Example Test
    Cart Add product to cart and verify quantity.
    Price Calculation Verify subtotal, discount, tax, and final amount.
    Coupon Apply valid and invalid coupon codes.
    Payment Check successful and failed payment scenarios.
    Order Confirmation Verify order ID and confirmation message.
    Regression Ensure old cart and payment features still work after updates.

    Best Practices for Testing

    Recommended Practices

    • Understand requirements before writing test cases.
    • Test both valid and invalid inputs.
    • Include edge cases and boundary values.
    • Write clear expected results.
    • Keep test cases simple and understandable.
    • Test small units before testing the full system.
    • Retest after fixing defects.
    • Perform regression testing after code changes.
    • Use meaningful defect reports.
    • Automate repeated tests when appropriate.
    • Keep test data organized.
    • Do not skip testing because the code “looks correct”.

    Common Beginner Mistakes

    Mistakes

    • Testing only with correct input.
    • Ignoring invalid input.
    • Not checking boundary values.
    • Not writing expected results clearly.
    • Testing only once and assuming everything is fine.
    • Not retesting after bug fixes.
    • Skipping regression testing.
    • Writing vague defect reports.

    Better Habits

    • Test valid, invalid, and edge cases.
    • Write clear test cases.
    • Compare actual result with expected result.
    • Retest fixed defects.
    • Check old features after new changes.
    • Use meaningful test data.
    • Log defects with clear details.
    • Make testing part of development habit.

    Prerequisites Before Learning Testing Basics

    Students should understand the following topics before learning testing deeply:

    Required Knowledge

    • Basic programming syntax.
    • Variables and data types.
    • Control flow and loops.
    • Functions or methods.
    • Clean code basics.
    • Debugging basics.
    • Requirement understanding.
    • Basic input and output concepts.

    Trace Table Example: Testing a Pass/Fail Program

    IF marks >= 40 THEN
        result = "Pass"
    ELSE
        result = "Fail"
    END IF
    Test Case Input Marks Expected Result Reason
    TC_001 50 Pass Marks are above 40.
    TC_002 40 Pass Boundary value.
    TC_003 39 Fail Just below boundary.
    TC_004 0 Fail Lowest valid value.

    Practice Activity: Write Test Cases

    Write test cases for the following requirement.

    Requirement:
    A user can withdraw money if:
    - Account balance is greater than or equal to withdrawal amount.
    - Withdrawal amount must be greater than 0.

    Sample Test Cases

    Test Case 1:
    balance = 1000, withdrawal = 500
    Expected Result: Withdrawal allowed
    
    Test Case 2:
    balance = 1000, withdrawal = 1000
    Expected Result: Withdrawal allowed
    
    Test Case 3:
    balance = 1000, withdrawal = 1200
    Expected Result: Withdrawal denied
    
    Test Case 4:
    balance = 1000, withdrawal = 0
    Expected Result: Invalid withdrawal amount
    
    Test Case 5:
    balance = 1000, withdrawal = -100
    Expected Result: Invalid withdrawal amount

    Mini Quiz

    1

    What is software testing?

    Software testing is the process of checking whether software works as expected and meets requirements.

    2

    What is a test case?

    A test case is a set of steps, inputs, and expected results used to verify a feature.

    3

    What is unit testing?

    Unit testing checks individual functions, methods, or components in isolation.

    4

    What is regression testing?

    Regression testing checks whether existing functionality still works after code changes.

    5

    What is the difference between expected and actual result?

    Expected result is what should happen, while actual result is what actually happens during testing.

    Interview Questions on Testing Basics

    1

    Why is testing important in software development?

    Testing is important because it helps find defects, verify requirements, improve quality, and reduce risk before software reaches users.

    2

    What are the main levels of testing?

    The main levels are unit testing, integration testing, system testing, and acceptance testing.

    3

    What is the difference between unit testing and integration testing?

    Unit testing checks individual units, while integration testing checks whether multiple units work correctly together.

    4

    What should a good test case include?

    A good test case should include test scenario, precondition, test steps, test data, expected result, actual result, and status.

    5

    Why should negative testing be performed?

    Negative testing is performed to check how the system handles invalid input, incorrect actions, and error situations.

    Quick Summary

    Concept Meaning
    Testing Checking whether software works as expected.
    Test Case Steps and data used to verify a feature.
    Unit Testing Testing individual functions or components.
    Integration Testing Testing interaction between modules.
    System Testing Testing the complete application.
    Acceptance Testing Testing whether users accept the software.
    Regression Testing Checking old features after new changes.
    Debugging Finding and fixing the cause of defects.

    Final Takeaway

    Testing basics help students understand how developers and testers verify software quality. Testing checks whether actual results match expected results, finds bugs early, and confirms that requirements are satisfied. Students should learn unit testing, integration testing, system testing, acceptance testing, regression testing, test cases, positive and negative testing, boundary values, and edge cases. Good testing improves reliability, reduces defects, and builds confidence before software is released.