Run unit tests and create mocks in C++ projects without manual registration
Test code runs automatically without manual registration, allowing you to catch errors in complex logic early. GoogleTest is a tool for unit testing and creating mock objects in C++ projects, maintained by integrating the previously separate GoogleTest and GoogleMock projects. The latest version, 1.18.0, requires C++17 or higher, and documentation is provided on GitHub Pages.
Automatic discovery and various verification methods
GoogleTest is based on the xUnit architecture and automatically finds and runs tests. You can use various built-in assertions for equality, inequality, and exception occurrence, and define custom assertions specific to your project. It supports death tests to verify that a process terminates in a specific way, which is useful for validating error handling code.
Parameterized tests and execution control
It supports value-parameterized tests, which run a function multiple times with different input values, and type-parameterized tests, which run with different data types. This is suitable for efficiently testing functions that handle various input conditions or types. Execution options are also diverse, allowing you to select individual test execution, specific order execution, or parallel execution.
Supported platforms and key use cases
GoogleTest follows Google's basic C++ support policy, and the list of currently supported compilers, platforms, and build tools can be found in the official documentation. It is used in large-scale open-source projects such as the Chromium project, the LLVM compiler, Protocol Buffers, and OpenCV.
Ecosystem of surrounding tools
Several open-source tools exist that can be used with GoogleTest. GTest Runner is a Qt5-based automated test runner, and GoogleTest UI is a test progress tracking tool written in C#. gtest-parallel is a tool that speeds up tests by running them in parallel. The VS Code extensions GoogleTest Adapter and C++ TestMate allow you to view and debug tests in a tree view. There are also listeners implementing the TAP protocol and Cornichon, a Gherkin DSL parser.
Pre-adoption considerations
From version 1.18.x onwards, the C++17 standard is a mandatory requirement, so you must check your project's compiler settings. Additionally, a dependency on the Abseil library is planned for the future, so you should consider the impact of this dependency on your project. Official documentation is now provided on GitHub Pages, so it is recommended to refer to the web documentation rather than the documentation in the repository. Google's internal systems are used for CI, but external users must configure their own CI environment.