UcenlyOpen in the app

Programming Essentials · BE5B33PRG · Topic 7 of 9

Exceptions, debugging and tests

Use failures as evidence and test observable behavior.

Open the interactive lesson

Key ideas

Traceback

Read the exception type and the call stack. Raise ValueError when an argument has an unacceptable value.

Handle narrowly

try: ... except ValueError: ... handles only the expected failure. Avoid silently swallowing unrelated errors.

Test cases

Test ordinary, empty and boundary inputs. unittest assertions compare expected with actual behavior.

Separate concerns

Keep functions deterministic where possible; a test can then call a function and check its return value.

In one line: Explain why a test case would catch a particular bug.

Sources

Written by Ucenly. Based on the BE5B33PRG course materials: