Programming foundations

Stage 5 · Lesson 6 of 10

Unit tests and edge cases

Object-oriented design and clean code

A calls one small piece of code with known inputs and checks the output automatically. So you know within seconds whether a change broke something. Each test has the same shape: arrange the inputs, act by calling the , then assert (check) the result.

Test the normal case first, then the : an empty list, one item, zero, negative numbers, the largest value and invalid input. Most bugs live at these edges. Use your language's standard , such as pytest, Vitest, JUnit, GoogleTest or xUnit, and run the tests from the terminal.

Tests only work on code that returns values instead of printing them, which is why came first.

A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Practise

  • Request mentoring on a solved exercise and ask specifically about naming and structure

Keep handy

  • Get started in 20 minutes: plain assert, fixtures and running tests from the terminal

Also worth your time

Mark this stage as not done?