Unit Tests with GoogleTest and GoogleMock
GoogleTest is a modern unit testing framework for C++. Due to its range of functions, robustness, and flexibility, it has become a quasi-industry standard. It is easy to use in industrial projects and supports cross-platform development. The structure of the framework is similar to older unit testing frameworks, making previously acquired knowledge applicable. Integration into continuous integration solutions is also already possible for many environments and very easy to achieve for the remaining ones.
GoogleTest shows its full potential when used in conjunction with GoogleMock. GoogleMock is an outstanding framework for simulating dependencies. Such simulation is particularly important for embedded development in order to isolate the logic from the behaviour of the target system. GoogleMock follows its own truly outstanding logic and goes far beyond the capabilities of traditional unit test frameworks.
The following topics will be covered:
Requirements for GoogleTest
- A C++ compiler with one of the language standards C++14 or C++17
- 500KB RAM on the test system, preferably more
- The standard output:
stdout - The pthread library
Basics
- Distinction between unit tests and integration tests, etc.
- Test maintainability
- Testing as documentation of the code
Introduction to GoogleTest
- How the framework works
- The „Triple A“ concept (Arrange, Act, Assertion)
- Nomenclature of test projects, suites, methods, and variables
- Assertions
- Exceptions
- Testing floating point numbers
- Testing exceptions
- The “death test”
- Test fixtures
- Parameterized tests
- Template parameterized tests
- Testing state machines
Integrating the framework into a software project
- The structure of the framework
- Compiling the framework
- Creating a library from the framework
- The test report
- The test report as XML, json, or HTML
- Programming the test report
- Ideas and practice of automatic test execution
GoogleMock
- Introduction to terms (stub, mock, fake, and spy)
- The concepts „Arrange, Expect, Act“
- Architectural requirements (e.g., dependency injection)
- Creating mocks
- Mock types (Nicemock, Strictmock, etc.)
- Matchers
- Mocking overloaded methods
- Mocking class templates
- Mocking non-virtual methods
- Mocking free functions
- Faking legacy code and third-party libraries
- Understanding Uninteresting and Unexpected Calls
- Ordered calls
- Mocking side effects
- Using functions/methods/functors/lambdas as actions
The framework is taught using practical examples. This requires a C++ compiler. The compiler should not be too old and should support the essential language features of ANSI/ISO C++ with regard to namespaces and naming conventions. It is important, of course, to use a platform that is familiar to the participants – preferably Windows or MacOSX or Linux. Of course, any UNIX system can also be used as a development and training platform for the course.
GoogleTest and GoogleMock are trademarks of Google LLC. This seminar is not affiliated with Google LLC and is not sponsored or endorsed by Google. It is a completely independent offering.
Last modified 2026-01-02