C++ Test-Driven Development

All developers want to build good quality software but not all developers test their software as they go along. Why not? A common explanation is "I don't have time to write tests!" The more pressure they feel, the fewer tests they write. This leads to less accurate and stable code, less productivity, less confidence and, ultimately, more pressure. It's a vicious cycle.

This course is designed to help you break out of the cycle by embracing unit-testing and, in particular, test-driven development. We will introduce the techniques and the tools necessary to prove your code as you go along.

The course makes use of GoogleTest during the labs and demos. If you’d like to use a different test framework instead, that can be arranged.


2 days



  • At least 3 months C++ programming experience

What you'll learn

  • Writing tests using GoogleTest
  • Using assertions and matchers
  • Adopting a test-driven approach to development
  • Using stubs and mock objects

Course details

Getting Started

  • Setting up a build system (e.g., using Bazel or CMake)
  • Writing and running a simple test using GoogleTest

Writing Effective Unit Tests

  • The AAA of unit testing
  • Using assertions
  • Running tests
  • Test statuses
  • Dealing with exceptions
  • Best practices

Going Further with Unit Testing

  • Performing setup and teardown operations
  • Using matchers effectively
  • Defining a custom matcher
  • Test suites

TDD and Agile Development

  • Understanding the TDD process
  • Test, code, refactor
  • TDD strategies
  • Refactoring techniques
  • Testing patterns
  • Best practice

Unit Testing with Mock Objects

  • Managing dependencies
  • Defining test doubles
  • Stubs, mocks, dummies, and fakes
  • Using gMock effectively