The cycle continues
All the techniques mentioned in the last section help us isolate pieces of code and break dependencies with other classes. This allows us to introduce stubs and mocks, making it easier to write more detailed characterization tests. The Extract Method refactoring is used a lot and is a great technique to isolate small sections of code.
The whole process is iterative. In a typical session, we might look at a piece of code via pdb
, and then decide to extract it to a method. We might then experiment with passing different inputs to the extracted method in the interactive shell, following which we might write a few characterization tests. We would then go back to another section of the class and write more tests after mocking or stubbing the new method, following which we might go back into pdb
or the interactive shell to take a look at another piece of code.
Throughout the process, we keep making small changes that are unlikely to break and keep running all our existing characterization...