Chapter 7. Agile testing: where dynamic typing shines

 

This chapter covers

  • The Python unittest module
  • Creating a test framework
  • Mock objects
  • Testing techniques: monkey patching and dependency injection
  • Functional testing

Testing is an increasingly important part of software development. Automated test suites allow you to easily include testing as part of your development process, rather than as a separate, time-consuming, and expensive manual process. The alternative is letting your customers find the bugs for you. Testing isn’t only about finding bugs early, though; writing code in a testable way encourages the writing of modular and loosely coupled code—which means better code. Additionally, when adding new features or refactoring, your tests can warn you about what other parts of your code you’ve broken. Fortunately, testing is an area where dynamic languages particularly shine.

There are many different ways of categorizing tests, and many names for subtly different styles of testing. Broadly speaking, the three categories of tests are as follow:

  • Unit tests
  • Functional tests[1]

    1 Also known as acceptance, integration, or black-box tests.

  • Regression tests

7.1. The unittest module

7.2. Testing with mocks

7.3. Functional testing

7.4. Summary

sitemap