GoogleTest: C++ testing and mocking framework
xUnit-based C++ testing framework with integrated mocking.
Learn more about googletest
GoogleTest is a C++ unit testing framework based on the xUnit architecture that automates test discovery and execution. It is implemented in C++ and requires C++17 or later as of version 1.17.0. The framework supports both fatal and non-fatal test failures, value-parameterized tests with multiple input values, type-parameterized tests across different data types, and death tests for verifying program exit behavior. It is used in large-scale projects including Chromium, LLVM, Protocol Buffers, and OpenCV for validating C++ code correctness.
Unified Testing Framework
Combines unit testing and mocking in a single maintained codebase, eliminating the need to manage separate GoogleTest and GoogleMock dependencies. Simplifies build configuration and version compatibility for projects requiring both capabilities.
Parameterized Test Variants
Supports value-parameterized tests with different input values and type-parameterized tests across multiple data types. Reduces code duplication when testing functions with varying inputs or validating generic implementations.
Death Test Support
Verifies that code properly terminates under expected conditions by testing exit codes and error messages. Death tests ensure crash handlers and fatal error paths work correctly without crashing the test runner itself.
#include <gtest/gtest.h>
int Add(int a, int b) { return a + b; }
TEST(MathTest, AdditionWorks) {
EXPECT_EQ(Add(2, 3), 5);
EXPECT_EQ(Add(-1, 1), 0);
EXPECT_NE(Add(2, 2), 5);
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}GoogleTest now requires C++17 minimum and follows Google's Foundational C++ Support Policy; no new features will be accepted on v1.17.x.
- –Upgrade to a C++17-compatible compiler and verify your toolchain against Google's supported versions table.
- –Use `--gtest_fail_if_no_test_linked` to catch empty test binaries and leverage `DistanceFrom()` matcher for numeric comparisons.
Last release supporting C++14; future versions require C++17. Bazel users must update repository references to canonical BCR names.
- –Update Bazel WORKSPACE repo_mapping if dependencies still use old repository names instead of Bazel Central Registry canonical names.
- –Expect testsuite properties exported as XML elements rather than attributes in test output files.
Maintenance release requiring C++14; no new features accepted on v1.15.x branch—build from HEAD for latest capabilities.
- –Ensure your toolchain meets C++14 minimum and follows Google's Foundational C++ Support Policy for compiler compatibility.
- –Adopt Bzlmod for Bazel builds; official support replaces community-maintained integration (registry availability lags release by days).
See how people are using googletest
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
plotly.py
Interactive browser-based charts from Python with declarative API.
redoc
React component rendering OpenAPI specifications as interactive HTML documentation.
ohmyzsh
Community-driven zsh configuration framework with modular plugins.
nvm
nvm is a per-user, per-shell version manager for Node.js that allows switching between multiple installed Node versions from the command line. It works on any POSIX-compliant shell across Unix, macOS, and Windows WSL environments.
redux-toolkit
Opinionated Redux utilities with simplified setup and Immer integration.