Chapter 5. Testing your software

 

This chapter covers

  • Understanding the anatomy of a test
  • Using different testing approaches for your application
  • Writing tests with the unittest framework
  • Writing tests with the pytest framework
  • Adopting test-driven development

I’ve talked in previous chapters about writing clear code using well-named functions for maintainability, but that’s only part of the picture. As you add feature after feature, can you be sure the application still does what you meant it to? Any application you hope will live on long into the future needs some assurances of its longevity. Tests can help you make sure new features are built correctly, and you can run these tests again each time you update your code to make sure it stays correct.

Testing can be a strict, formal process for applications that must not fail, like launching shuttles and keeping planes in flight. Such tests are rigorous and often mathematically provable. That’s pretty cool, but it goes way beyond what’s necessary or practical for most Python applications. In this chapter, you’ll learn about the methodology and tools Python developers use to test their code, and you’ll get a chance to write some tests yourself.

5.1. What is software testing?

5.1.1. Does it do what it says on the tin?

5.1.2. The anatomy of a functional test

5.2. Functional testing approaches

5.2.1. Manual testing

5.2.2. Automated testing

5.2.3. Acceptance testing

Testing is for everyone

5.2.4. Unit testing

5.2.5. Integration testing

5.2.6. The testing pyramid

5.2.7. Regression testing

Version control hooks

5.3. Statements of fact

5.4. Unit testing with unittest

5.4.1. Test organization with unittest

5.4.2. Running tests with unittest

5.4.3. Writing your first test with unittest

5.4.4. Writing your first integration test with unittest

5.4.5. Test doubles

5.4.6. Try it out

5.4.7. Writing interesting tests

5.5. Testing with pytest

5.5.1. Test organization with pytest

5.5.2. Converting unittest tests to pytest

5.6. Beyond functional testing

5.6.1. Performance testing

5.6.2. Load testing

sitemap