Book Image

Test-Driven Python Development

By : Siddharta Govindaraj
Book Image

Test-Driven Python Development

By: Siddharta Govindaraj

Overview of this book

This book starts with a look at the test-driven development process, and how it is different from the traditional way of writing code. All the concepts are presented in the context of a real application that is developed in a step-by-step manner over the course of the book. While exploring the common types of smelly code, we will go back into our example project and clean up the smells that we find. Additionally, we will use mocking to implement the parts of our example project that depend on other systems. Towards the end of the book, we'll take a look at the most common patterns and anti-patterns associated with test-driven development, including integration of test results into the development process.
Table of Contents (20 chapters)
Test-Driven Python Development
About the Author
About the Reviewers

Pattern – fast tests

One of the key goals of TDD is to write tests that execute quickly. We will be running the tests often when doing TDD— possibly even every few minutes. The TDD habit is to run the tests multiple times when developing code, refactoring, before checkins, and before deployments. If tests run any longer, we will be reluctant to run them often, which defeats the purpose of the tests.

With that in mind, some techniques for keeping tests fast are as follows:

  • Disable unwanted external services: Some services are not central to the purpose of the application and can be disabled. For instance, perhaps we use a service to collect analytics on how users use our application. Our application might be making a call to this service on every action. Such services can be disabled, enabling tests to run faster.

  • Mock out external services: Other external services such as servers, databases, caches, and so on might be central to the functioning of the application. External services take time...