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
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Techniques to break dependencies


Now that we've seen some techniques to help us understand the code, our next step is to break dependencies. This will help us write further characterization tests. To do this, we will very carefully start modifying the code. All the while, we will try to stick to the following goals:

  • Make small changes that are very unlikely to break

  • Try to change the public interface as little as possible

Why these goals? Because we have a lack of tests, we have to be careful with the changes we make. Hence, small changes are better. We also need to be careful of changing the public interface because we have to go and fix all the other files and modules that use this class.

The Rope refactoring library

The Rope refactoring library is a library to perform automated refactoring of your code. For example, you could select a few lines and then type the command to extract it into a method. The library will automatically create this method with the appropriate code, parameters, and...