Test all the Things

Untested code is broken code.

- Unknown

Testing can be used to show the presence of bugs, but never to show their absence!

 — Edsger W. Dijkstra

Video

Software Testing

Testing is probably the most important topic in software engineering. This is because malfunctioning software can have dire consequences, like causing a multi-million dollar satellite to crash into mars, flashing the infamous blue screen of death during a live demo, or bankrupting an entire financial firm in a few minutes by losing $440 million dollars in bad trades. There have also been high profile bugs in scientific software, like when protein structure analysis code swapped two data columns producing spurious results that lead to a retraction of five research papers, hundreds of hours of wasted research time, and a ruined career. Testing is our main defense against such spectacular failures, and the way we gain confidence that a code works.

Testing strategies are varied, from manually testing a code as it is written, to creating a massive suite of automated tests that run every line (or branch) of the code under test, sometimes dynamically changing test inputs or even the code itself! Under-testing a code means failures are more likely, but over testing can cause blown budgets and missed deadlines. The appropriate testing strategy and rigor depends on the nature and requirements of the code.

Moreover, many argue writing software that is easily testable, like when tests are written before the software, helps create more modular robust code. This is one of the common arguments behind the Test Driven Development movement.

In Python, the most popular framework for automated testing is pytest. Pytest is a powerful tool that greatly improves testing, but like all tools, takes some time to learn.

Testing concepts and the pytest framework could both be a whole course (or several courses). Here we simply try to highlight some of the main ideas and provide the basics of pytest.

Overview

In this module, we will cover:

  1. Software testing approaches and domains
  2. Basics of the pytest framework

Reading

Additional Resources