Summary and Schedule
This is a new lesson built with The Carpentries Workbench.
| Setup Instructions | Download files required for the lesson | |
| Duration: 00h 00m | 1. Introduction | What are the goals of this course? |
| Duration: 00h 12m | 2. Why Test My Code? | Why should I test my code? |
| Duration: 00h 24m | 3. Simple Tests |
How to write a simple test? How to run the test? |
| Duration: 00h 36m | 4. Interacting with Tests |
How do I use pytest to run my tests? What does the output of pytest look like and how do I interpret it? |
| Duration: 00h 48m | 5. Unit tests & Testing Practices |
What to do about complex functions & tests? What are some testing best practices for testing? How far should I go with testing? How do I add tests to an existing project? |
| Duration: 01h 00m | 6. Testing for Exceptions | How to check that a function raises an exception? |
| Duration: 01h 12m | 7. Floating Point Data |
What are the best practices when working with floating point
data? How do you compare objects in libraries like numpy?
|
| Duration: 01h 27m | 8. Fixtures | How to reuse data and objects in tests? |
| Duration: 01h 39m | 9. Parametrization | Is there a better way to test a function with lots of different inputs than writing a separate test for each one? |
| Duration: 01h 51m | 10. Regression Tests |
How can we detect changes in program outputs? How can snapshots make this easier? |
| Duration: 02h 04m | 11. Continuous Integration with GitHub Actions |
How can I automate the testing of my code? What are GitHub Actions? |
| Duration: 02h 49m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Testing and Continuous Integration
This course aims to equip you with the tools and knowledge required to get started with software testing. It assumes no prior knowledge of testing, just basic familiarity with Python programming. Over the course of these lessons, you will learn what software testing entails, how to write tests, best practices, some more niche & powerful functionality and finally how to incorporate tests in a GitHub repository.
Software Setup
Please complete these setup instructions before the course starts. This is to ensure that the course can start on time and all of the content can be covered. If you have any issues with the setup instructions, please reach out to a course instructor / coordinator.
For this course, you will need:
A Text Editor
Preferably a code editor like Visual Studio Code but any text editor will do, such as notepad. This is so that you can write and edit Python scripts. A code editor will provide a better experience for writing code in this course. We recommend Visual Studio Code as it is free and very popular with minimal setup required.
A Terminal
Such as Terminal on MacOS / Linux or command prompt on Windows. This is so that you can run Python scripts and commit code to GitHub. Note that Visual Studio Code provides both a terminal and Git integration.
Python
Preferably Python 3.12 or higher. You can download Python from Python’s official website.
It is recommended that you use a virtual environment for this course. This can be a standard Python virtual environment or a conda environment. You can create a virtual environment using the following commands:
BASH
# For a standard Python virtual environment
python -m venv venv
# Linux
source venv/bin/activate
# Windows (powershell)
.\venv\Scripts\Activate.ps1
# For a conda environment
conda create --name myenv
conda activate myenv
There are some python packages that will be needed in this course, you can install them using the following command:
Git
This course touches on some features of GitHub and requires Git to be installed. You may find it helpful to view the material from our course Introduction to Git and GitHub.
A GitHub account
A GitHub accound is required for the Continuous Integration section of this course. You can sign up for a GitHub account on the GitHub Website