Test Driven Development with unittest

In this section, you will learn about Test Driven Development (TDD) with Python using Python’s built-in unittest module. I do want to thank Matt and Aaron for their assistance in showing me how TDD works in the real world. To demonstrate the concepts of TDD, we’ll be covering how to score bowling in Python. You may want to use Google to look up the rules for bowling if you don’t already know them. Once you know the rules, it’s time to write some tests. In case you didn’t know, the idea behind Test Driven Development is that you write the tests BEFORE you write the actual code. In this chapter, we will write a test, then some code to pass the test. We will iterate back and forth between writing tests and code until we’re done. For this chapter, we’ll write just three tests. Let’s get started!

The First Test

Our first test will be to test our game object and see if it can calculate the correct total if we roll eleven times and only knock over one pin each time. This should give us a total of eleven.

Get hands-on with 1200+ tech skills courses.