Learn: Unit testing¶
Four short tutorials that build up your working knowledge of unittest, from a single test method to fixtures shared across a class. Each one is a Jupyter notebook — read it in the browser, and edit and run any code cell directly on the page.
The tutorials build on each other, so working through them in order is the fastest path. Each takes roughly fifteen to twenty minutes.
The sequence¶
- Your first test — writing a
TestCase, an assertion, and running it. - Testing thoroughly — choosing inputs, covering edge cases, and what "thorough" actually looks like.
- Testing best practices — naming, structure, and habits that make tests readable a year later.
- Test fixtures —
setUp,tearDown, and sharing setup across tests without coupling them.
Before you start¶
You'll get more from these if you're already comfortable with Python functions and classes. The Functions guide is a good warm-up.
You don't need Python installed locally — every tutorial runs in your browser. If you'd rather run them on your own machine, each notebook has a download button in the top-right corner.