· intermediate
Testing Python Code
Write tests that catch real mistakes and survive a refactor. What to assert, how to structure a suite with unittest, testing the failure paths, and replacing the awkward parts with test doubles.
Written in house, from the work rather than from a syllabus. Every example is one we would use ourselves, and every exercise is checked against the same engine that grades your answer.
What you’ll learn
- Write an assertion that reports what actually went wrong
- Structure a test as arrange, act, assert
- Choose what to test, and recognise a test that only repeats the code
- Group tests in a TestCase and share setup without sharing state
- Assert that the right exception is raised for the right reason
- Replace a slow or awkward dependency with a fake you control
Before you start
- · Comfortable writing functions and classes
- · Familiar with exceptions and raising them