From the course: Unit Testing and Test Driven Development in Python

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

TDD best practices

TDD best practices

- [Instructor] There are a lot of things you can do to help with your practice of implementing unit tests using test-driven development. In this lecture I'll go over some best practices that I have found that are essential to making TDD productive. First, you should always do the next simplest test case. This allows you to gradually increase the complexity of the code, refactoring as you go. This helps keep your code clean and understandable. If you jump to the complex cases too quickly, you can find yourself stuck writing a lot of code for one test case which breaks the short feedback cycle we look for with TDD. Beyond just slowing you down, this can also lead to bad design as you can miss some simple implementations that come from the incremental approach. Always try to use descriptive test names. The code is read thousands of times more than it's written as the years go by. Making the code clear and understandable should be the top priority. Unit tests are the best documentation…

Contents