Unit testing and TDD for beginners: red, green, refactor
11 steps · about 6 h 34 min · Beginner
- The Practical Test Pyramid (article, Martin Fowler (Ham Vocke), 30 min)
Start by learning what a unit test is and why a test suite should have mostly small, fast ones.
- Getting Started With Testing in Python (article, Real Python, 30 min)
You write and run your first Python tests with the built-in unittest tools, so the basic ideas are in place before pytest.
- Get Started - pytest documentation (doc, pytest.org, 15 min)
The official quick start installs pytest and shows the plain assert style you'll use for the rest of the list.
- Test-Driven Development With pytest (video, Real Python (Chyld Medford), 55 min)
A short video course that walks through the core TDD cycle step by step, with exercises.
- Test-driven development (reference, Wikipedia, 15 min)
Gives the vocabulary and history of red/green/refactor, so you can see why the cycle works.
- Test-Driven Development in Python: pytest Tutorial (tutorial, istranin.dev, 30 min)
Follow one failing test at a time to build a small class, and meet pytest.raises and parametrize in context.
- pytest Tutorial: Effective Python Testing (article, Real Python, 49 min)
Goes deeper on fixtures, parametrization, marks and plugins once you've done the TDD loop.
- How to parametrize fixtures and test functions (doc, pytest.org, 15 min)
Lets you cover many inputs and edge cases with one test function, using the official reference.
- unittest.mock — getting started (doc, Python docs, 25 min)
Teaches you to replace slow or unpredictable dependencies with mocks, which keeps unit tests isolated.
- TDD with Python and pytest: Step-by-Step Tutorial (tutorial, HelpMeTest, 40 min)
A second full red-green-refactor project, an order pricer, so you can practise the loop on fresh code.
- Pytest Tutorial – How to Test Python Code (video, freeCodeCamp.org (YouTube), 1 h 30 min)
A long video to finish with, reviewing pytest features and best practices from start to finish.