Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Testing

Learning Goals

By the end of this section you will:

  • understand the importance of testing and documenting this testing

  • know how to perform and document unit tests

  • know how to perform and document integrated test

In the Good Programming Practice section we have already mentioned the three different types of testing:

Unit testing and integrated testing are excellent evidence of problem solving, refinement and justification for evaluation. In such, it is important to document this testing.

Unit testing

Unit testing is a method where individual parts of a program, called units, are tested to ensure they work correctly.

Imagine a program as a complex machine made of smaller parts, like gears. Each gear needs to work perfectly for the whole machine to function. In unit testing, developers write tests for these ‘gears’ – which could be functions or methods – to check if they perform as expected when given certain inputs.

If a test fails, it means there’s a problem with that part of the code, and it needs fixing before it can be used with other parts of the program. If unit passes all the tests, then the programmer can be confident that any future errors are not caused by this unit, therefore will not need to test it again unless its code is changed.

This approach helps catch errors early and simplifies debugging, making the development process more efficient and the final program more reliable.

Performing Unit Tests

Follow these steps to run your unit tests:

  1. Complete a function or component:

    • Once you have completed a function or component, you can test it.

    • If the code calls other parts of your code, you need to ensure that code has previously passed a unit test.

  2. Plan test cases:

    • Think of different situations the function should handle:

      • Normal/expected input

      • Boundary cases - values are at the edge of acceptable ranges, such as the smallest or largest valid number

      • Invalid input

  3. Run the function manually:

    • Use print statements to run your function with your test cases.

    • You make create a sperate Python file for testing

  4. Compare actual vs expected output

    • Check if what the function returned matches what you expected.

    • If not, investigate the error.

  5. Refine your code if needed

    • If it failed any test, change the code and test again.

  6. Record results

    • Keep a simple table of results:

Test caseInputExpected OutcomeActual OutcomePass/FailAction
1add(2, 3)55Passn/a
2add(-1, 1)00Passn/a
3add(“a”, 2)ErrorCrashFailused try except block
3add(“a”, 2)ErrorErrorPassn/a

Integrated testing

Integration testing is a phase in software testing where individual pieces of an application, often called units or modules, are combined and tested together as a group. The main goal of this testing is to check if these different parts work well together. For example, in a social media app, integration testing might involve checking if the part that handles user logins correctly interacts with the part that shows friends’ posts.

Integration testing allows testers to find and fix problems where the different parts of the software fail to properly communicate or work together.

In your projects, you will use integrated testing to ensure the effectiveness of your solution.

Performing Integrated Tests

Follow these steps to run your integrated tests:

  1. Identify components to test together

    • E.g. user input → processing → database update → output display.

  2. List success criteria

    • Use the ones you defined during solution planning (e.g. “Data must save correctly”, “User sees confirmation message”).

  3. Create test scenarios

    • Describe real-world situations that involve multiple parts:

      • “Student logs in and updates their profile”

      • “User submits a form and sees a result”

  4. Run each scenario manually

    • Follow the full process like an actual user would.

  5. Check system behaviour against each success criterion

    • Did all components trigger correctly?

    • Was the result correct and visible to the user?

    • Did the system handle errors?

  6. Refine solution if needed

    • Fix issues and re-test until all success criteria are met.

  7. Record results

    • Keep a simple table of results:

ScenarioExpected OutcomePass/FailAction
Student submits feedback formData saved to databasePassn/a
Student submits feedback formConfirmation displayedPassn/a
Student submits feedback formSystem prevents blank submissionFailadded UI error message
Student submits feedback formSystem prevents blank submissionPassn/a