Overview

Writing tests for your code is a vital part of any well-design software project, however there is a school of thought that writing tests before you even start your project is the best approach. This is ‘test-driven development’ and it takes a bit of practice to get the hang of, which will be the goal for today’s class.

Basic Learning Objectives

Before class, you should be able to:

  • Explain the basic philosophy behind test-driven development
  • Define the terms ‘unit test’ and ‘integration test’
  • Explain the basic workflow ‘red-green-refactor’ in Python using unittest

Advanced Learning Objectives

After class, you should be able to:

  • Argue about the pros and cons of writing unit tests as a mechanism for developing and testing functions
  • Use ‘unittest’ to write tests in Python
  • Identify edge cases for a basic project

Readings

To achieve the basic learning objectives, you should read the following:

  • Read the Wikipedia article on Test-Driven Development (TDD). The core idea here is very simple, but as you’ll see from the Wikipedia article, it has accumulated a lot of formalism. Read from the beginning up through the “Limitations” section.
  • Getting Started with Testing in Python. Read up to but not including Testing for Web Frameworks like Django and Flask.
  • Optional: Clean Code Ch 9 - goes more into specific tips from the pros and ‘war stories’

Checks

Write down answers to the following and bring them to class:

  • What are the steps to test-driven development?
  • What is the basic structure of a test using ‘unittest’?
  • How do you run your tests using ‘unittest’?