this is the final benefit of test-driven developmentand the most important once the tests are writtenwe can improve our code as much as we like and be confident that our changes didn' break anything we have been testing for furthermorewe know exactly when our refactor is finishedwhen the tests all pass of courseour tests may not comprehensively test everything we need them tomaintenance or code refactoring can still cause undiagnosed bugs that don' show up in testing automated tests are not foolproof if bugs do occurhoweverit is still possible to follow test-driven planstep one is to write test (or multiple teststhat duplicates or "provesthat the bug in question is occurring this willof coursefail then write the code to make the tests stop failing if the tests were comprehensivethe bug will be fixedand we will know if it ever happens againas soon as we run the test suite finallywe can try to determine how well our tests operate on this code with the py test coverage plugin installedpy test -coverage-report=report tells us that our test suite has percent code coverage this is great statisticbut we shouldn' get too cocky about it our code hasn' been tested when encoding messages that have numbersand its behavior with such inputs is thus undefined exercises practice test-driven development that is your first exercise it' easier to do this if you're starting new projectbut if you have existing code you need to work onyou can start by writing tests for each new feature you implement this can become frustrating as you become more enamored with automated tests the olduntested code will start to feel rigid and tightly coupledand will become uncomfortable to maintainyou'll start feeling like changes you make are breaking the code and you have no way of knowingfor lack of tests but if you start smalladding tests will improvethe codebase improves over time so to get your feet wet with test-driven developmentstart fresh project once you've started to appreciate the benefits (you willand realize that the time spent writing tests is quickly regained in terms of more maintainable codeyou'll want to start writing tests for existing code this is when you should start doing itnot before writing tests for code that we "knowworks is boring it is hard to get interested in the project until you realize just how broken the code we thought was working really is try writing the same set of tests using both the built-in unittest module and py test which do you preferunittest is more similar to test frameworks in other languageswhile py test is arguably more pythonic both allow us to write object-oriented tests and to test object-oriented programs with ease