Unit testing and TDD for beginners: red, green, refactor

11 steps · about 6 h 34 min · Beginner

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. Test-driven development (reference, Wikipedia, 15 min)

    Gives the vocabulary and history of red/green/refactor, so you can see why the cycle works.

  6. 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.

  7. 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.

  8. 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.

  9. unittest.mock — getting started (doc, Python docs, 25 min)

    Teaches you to replace slow or unpredictable dependencies with mocks, which keeps unit tests isolated.

  10. 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.

  11. 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.