Introduction to testing C++ code

This course teaches the fundamental concepts and skills required to design effective test suites for modern C++ software.

The consequences of writing buggy software can range from the mild to the catastrophic, but one thing remains invariant: many bugs can be discovered and fixed quickly with a well designed and maintained suite of tests. Well tested code inspires confidence in stakeholders, and the absence of tests is often viewed as an unacceptable liability, particularly in scientific and engineering applications.

To ensure that your software continues to meet the increasingly stringent expectations of users and stakeholders in a sustainable and future-proof way, we will learn to implement modern software testing concepts, such as fixtures and parametrised testing using the popular GoogleTest C++ testing framework.


Learning outcomes

After completing this workshop, you will understand:

  1. The usefulness and importance of software testing.
  2. How to write effective C++ tests using GoogleTest.
  3. How to automate test preparation and cleanup with test fixtures.
  4. How to easily test ranges of inputs with parametrised tests.
  5. How to simulate other code in tests with test doubles.

Delivery of the course

Material will be delivered as a lecture with task following the Carpentries teaching style.


A working knowledge of C++ programming is essential.


Setup Download files required for the lesson
00:00 1. Introduction to testing Why test my software?
How can I test my software?
How much testing is ‘enough’?
00:30 2. Introduction to Unit Testing using GoogleTest What framework/libraries can be used for unit testing in C++?
What is GoogleTest?
How can I write and run unit tests with GoogleTest?
01:15 3. Introduction to Test Fixtures using GoogleTest What is a test fixture?
How can I create my own test fixture using GoogleTest?
What do Setup and Teardown mean in relation to test fixtures?
02:00 4. Parameterised Tests using GoogleTest What is a parameterised test?
How can I write my own parameterised tests using GoogleTest?
How to use test fixtures with parameterised tests?
02:45 5. Tests doubles and dependency injection What are test doubles?
What types of test doubles are there?
How do I configure and run tests with Google Mocks?
03:30 6. General unit testing best practice What are some best practices that should be followed when writing unit tests?
04:00 Finish

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