Testing

Testing in Software Development

Testing ensures that a program works as expected and is free of errors. It is a crucial step in software development to verify the functionality, performance, and reliability of a program.

Types of Testing

Iterative Testing

Definition: Iterative Testing

Testing parts of the program during development. To find and fix errors early in the development process.

Final/Terminal Testing

Definition: Final Testing

Testing the entire program after development is complete. To ensure the program works correctly before release.

Identifying Errors

Definition: Syntax Errors

Errors that break the grammatical rules of the programming language, preventing the program from running or being translated.

Syntax Error Example

# there are two syntax errors here
prit("Hello, world") # print is spelt incorrectly
print("hi) # the string is not closed

Definition: Logic Errors

Errors that result in incorrect or unexpected output, even though the program runs.

Logic Error Example

# this program runs and is supposed to print 1 to 10
for i in range (10):
  print(i) # i will start at 0, so it needs to say print(i+1)

Syntax errors will often be picked up with help from your IDE which will provide clues through syntax highlighting. If not then you will usually get an error also at runtime, often with a bit of feedback to say where the error is.

Logic errors will only be picked up with robust testing of your code. It might require you to then debug that error to figure out where you have made the mistake. This could be done manually with a trace table or you could use the built in debugger to step through your code tracing through the variables to see where they change.

Selecting and Using Suitable Test Data

Types of Test Data

  • Normal Test Data: Data that is expected and should be processed without errors.

    • Example: For a program accepting ages 0-120, normal data would be 25, 50, etc.
  • Boundary Test Data: Data at the edge of valid ranges.

    • Example: For ages 0-120, boundary data would be 0, 120.
  • Invalid Test Data: Data that is of the correct type but should not be accepted.

    • Example: For ages 0-120, invalid data would be -1, 121.
  • Erroneous Test Data: Data of the incorrect type that should be rejected.

    • Example: For ages 0-120, erroneous data would be "twenty-five", "abc".

Creating a Test Plan

  1. Identify Test Cases: Determine which parts of the program to test.
  2. Select Test Data: Choose normal, boundary, invalid, and erroneous data.
  3. Execute Tests: Run the program with the selected test data.
  4. Document Results: Record the outcomes of each test case.

Using these methods ensures that your program is thoroughly tested and any issues are identified and resolved before deployment.

Example Test Plan

def is_valid_age(age):
    if 0 <= age <= 120:
        return True
    else:
        return False
  • This function is used to check that someone has entered a valid age into a computer system
  • It accepts ages from the range of 0 through to and including 120

Explanation

  • Normal Data: Test with a typical valid age (25).
  • Boundary Data: Test with edge cases (0 and 120).
  • Invalid Data: Test with ages outside the valid range (-1 and 121).
  • Erroneous Data: Test with non-integer input ('twenty-five').
Test TypeDescriptionInputExpected OutputActual OutputPass/Fail
Normal DataValid age in range25TrueTruePass
Boundary DataLower limit0TrueTruePass
Boundary DataUpper limit120TrueTruePass
Invalid DataBelow lower limit-1FalseFalsePass
Invalid DataAbove upper limit121FalseFalsePass
Erroneous DataNon-integer string'twenty-five'FalseFalsePass
Previous
Trace tables