icon icon

Test-Driven Development (TDD) in Python – a step-by-step introduction

icon

Training process

Training needs analysis

If you have specific requirements regarding the training programme, we will carry out a training needs analysis for you. This will guide us on which aspects of the programme should receive greater emphasis, so that the training programme meets your specific needs.

What will you gain?

icon

Understand the TDD cycle - You will learn to work deliberately in the Red–Green–Refactor loop, so you can build code in small steps, catch defects earlier, and keep your project easier to maintain over time.

icon

Write Python tests - You will practice creating unit tests with unittest and pytest, so you can write your own tests with clear assertions, exception checks, and a structure ready for real project work.

icon

Start with a test - You will go through your first TDD iterations from an empty task to a working solution, helping you define expected behavior before implementation and make coding decisions with more confidence.

icon

Test functions and classes - You will learn how to test simple functions as well as class and method behavior, which will help you design code that is more predictable, modular, and easier to extend safely.

icon

Organize test scenarios - You will use setUp, tearDown, and test parameterization to build repeatable scenarios faster, reduce duplication, and keep larger test suites easier to read and maintain.

icon

Isolate external dependencies - You will learn mocking and stubbing for code that depends on APIs, databases, or files, so you can verify application logic without relying on unstable or slow external systems.

icon

Avoid common pitfalls - You will see when to choose unit tests and when integration tests make more sense, how to avoid overengineering, and how to keep tests useful instead of turning them into overhead.

icon

Apply TDD in a project - While building a simple application, you will practice the full TDD workflow in context, making it much easier to transfer this approach into your own everyday development tasks.

Training programme

1. Introduction to TDD

  • What is Test-Driven Development and why is it worth using?
  • Differences between the traditional approach and TDD,
  • The Red – Green – Refactor cycle,
  • The most common misconceptions about TDD.

2. Basics of testing in Python

  • introduction to unittest – the standard testing framework in Python,
  • alternative: pytest – faster and simpler testing,
  • structure of a simple unit test,
  • example assertions (assertEqual, assertTrue, assertRaises, etc.).

3. First steps with TDD

  • writing the first test before writing the code,
  • creating minimal code that satisfies the test,
  • refactoring after the test passes,
  • repeating the cycle for the development of greater functionality.

4. TDD on functions and classes

  • testing functions: bottom-up approach,
  • testing classes and methods – testing object behaviors,
  • creating setups (setUp) and teardowns (tearDown) in tests.

5. Advanced testing techniques

  • mocking and stubbing in tests (unittest.mock),
  • testing code dependent on API, databases, files,
  • parameterization of tests using pytest.mark.parametrize,
  • organization of larger test suites in the project.

6. Best practices in TDD

  • when to write unit tests, and when integration tests?
  • tests and code documentation,
  • how to avoid overengineering in tests?
  • typical pitfalls in TDD and how to avoid them.

6. Best practices in TDD

  • when to write unit tests, and when integration tests?
  • tests and code documentation,
  • how to avoid overengineering in tests?
  • typical pitfalls in TDD and how to avoid them.

7. Practical project

  • development of a simple application (e.g. task management system, mini API),
  • application of TDD at every stage of the project,
  • refactoring with the use of tests.

What are the prerequisites for participating in the training?

icon

Python basics - You should be comfortable with basic Python syntax, including functions, conditionals, loops, and working with data, so you can follow examples and write your own code.

icon

Working with classes - You should understand what classes, objects, and methods are in Python, because during the training you will test object behavior and build simple code structures.

icon

Running Python code - You should be able to run a Python script from the terminal or your development environment, so you can execute tests smoothly and review each iteration as you go.

icon

Project basics - It will help if you already know how to read simple code and move around a project structure, because you will work with test files and code developed step by step.