Automated testing - Preventing yourself and others from breaking your functioning code

Have you ever had some of these problems?:

  • You change B and C, and suddenly A doesn’t work anymore. Time wasted trying to figure out what changed.

  • There was some simple problem, systematically testing could have found it.

  • You get someone else’s code and are afraid to touch it because who knows what might break. Plot twist: it’s your own code!

People have learned that some automatic way to check problems makes software development much easier. This lesson will talk about the places it’s useful for research code, and how easy it can be. We will discuss why testing often needs to be part of the software development cycle and how such a cycle can be implemented. We will see how automated testing works and practice designing and writing tests.

Prerequisites

  1. You need pytest (as part of Anaconda or Miniconda or Virtual Environment).

  2. (Optional) To work on exercises in other languages than Python, please follow the instructions under “Language-specific instructions” in the Test design episode to install the recommended testing frameworks.

  3. Basic understanding of Git.

  4. You need a GitHub or a Gitlab account for the “automated testing” and “full-cycle collaborative workflow” (but the rest works fine just locally).

15 min

Motivation

25 min

Testing locally

30 min

Automated testing

30 min

Test design

5 min

Conclusions and recommendations