Skip to Content
Robust Python
book

Robust Python

by Patrick Viafore
July 2021
Intermediate to advanced
378 pages
9h 35m
English
O'Reilly Media, Inc.
Book available
Content preview from Robust Python

Chapter 21. Testing Strategy

Tests are one of most important safety nets you can build around your codebase. It is incredibly comforting to make a change and see that all tests pass afterwards. However, it is challenging to gauge the best use of your time regarding testing. Too many tests and they become a burden; you spend more time maintaining tests than delivering features. Too few tests and you are letting potential catastrophes make it into production.

In this chapter, I will ask you to focus on your testing strategy. I’ll break down the different types of tests and how to choose which tests to write. I’ll focus on Python best practices around test construction, and then I’ll end with some common testing strategies specific to Python.

Defining Your Test Strategy

Before you write tests, you should decide what your test strategy will be. A test strategy is a plan for spending time and effort to test your software in order to mitigate risk. This strategy will influence what types of tests you write, how you write them, and how much time you spend writing (and maintaining) them. Everybody’s test strategy will be different, but they will all be in a similar form: a list of questions about your system and how you plan on answering them. For example, if I were writing a calorie-counting app, here would be a part of my test strategy:

Does my system function as expected? Tests to write (automated - run daily): Acceptance tests: Adding calories to the daily count Acceptance tests: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Dead Simple Python

Dead Simple Python

Jason C. McDonald
Fluent Python

Fluent Python

Luciano Ramalho

Publisher Resources

ISBN: 9781098100650Errata PageSupplemental Content