Test-driven development (TDD) is a methodology that aims to produce high-quality software by concentrating on automated tests. It is widely used in the Python community, but it is also very popular in other communities.
Testing is especially important in Python due to its dynamic nature. Python lacks static typing, so many, even minute, errors won't be noticed until the code is run and each of its lines is executed. But the problem is not only how types in Python work. The most troublesome bugs are not related to bad syntax or wrong type usage, but rather to logical errors and subtle mistakes that may lead to major failures.
In order to efficiently test your software, you often need to use a wide variety of testing strategies that will be executed on different abstraction levels of your application. Unfortunately, not every testing strategy is suitable for every project, and not every testing framework will be suitable for every kind of testing strategy. This is why it's not uncommon for larger projects to use multiple testing libraries and frameworks that fulfill different (often overlapping) testing needs. So, in order to better guide you through the sophisticated world of software testing and test-driven development, this chapter is split into the following two parts:
- I don't test, which advocates TDD and quickly describes how to do it with the standard library
- I do test, which is intended for developers who practice tests and wish to get more out of them