This lesson is being piloted (Beta version)

Introduction to automated testing and continuous integration in Python

Testing is a vital part of software development. Without it, we have no guarantee that the results that our software gives are correct, for any definition of “correct”. While we all almost always do some checks when writing software that the bit we’ve just written does what we think it was going to, as our software grows in complexity then our work starts to have side-effects on other sections of the application which we may not think to re-test. Automating our testing allows us to verify all functionality in the application after every step of development, giving us an easier way of checking that everything is as we expect. In this lesson we will look at using pytest to test software written in Python, but tools for automated testing are available for most languages.

Continuous Integration (CI) takes automated testing to the next step, automatically running your tests whenever anyone commits and pushes a new revision of a piece of software to a repository. This means that even if you don’t remember to run your tests yourself, you will still be made aware of any ways in which the software has stopped working as expected. In this lesson we will focus on the CI tools provided by GitHub; other services such as GitLab also provide their own CI tools, as do other providers like CircleCI.

Prerequisites

While automated testing tools are available in any language, this lesson relies on understanding the Python programming language. Continuous Integration requires working with a version control system, and in this lesson we will focus on Git. We will also make use of the Unix Shell to run the Python examples and interact with Git. If any of these concepts are unfamiliar, then we would recommend reviewing the Software Carpentry lessons for Python, Git, and the Unix Shell, respectively.

Schedule

Setup Download files required for the lesson
00:00 1. Automating tests Why is automating tests important?
What tools are available to help me automate tests?
How can I use these tools to automate simple tests?
00:25 2. pytest features How can I avoid repetition when writing similar tests?
How can I test cases that I expect to raise exceptions?
How can I test that documentation is up to date?
00:50 3. Input data for tests How can I avoid repetition when defining input data for tests?
How can I re-use test data that take significant time to generate?
01:15 4. Edge and corner cases, and integration testing What considerations are there when testing problems with boundaries?
What are unit and integration tests?
01:40 5. Testing randomness How can I test non-deterministic applications?
02:05 6. Continuous Integration How can my tests run automatically?
02:30 7. Code coverage How can I see how much of my code is tested?
How can I check code coverage as part of a CI workflow?
02:55 8. Putting it all together How can I apply all of these techniques at once to a real application?
04:30 Finish

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.