CheckOps home

Tools directory

G

CheckOps

GoogleTest

GoogleTest is Google's BSD-3-Clause C++ test framework, merged with GoogleMock, providing xUnit-style tests, rich assertions, death tests, parameterised and typed tests, and C++ mocking.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

GoogleTest is Google’s C++ test framework. Its repository is a merger of the formerly separate GoogleTest and GoogleMock projects, which the README says were so closely related that it made sense to maintain and release them together. It is licensed BSD-3-Clause and is one of the most widely used C++ testing libraries, with about 39,700 GitHub stars.

The README describes GoogleTest as an xUnit test framework and lists its main capabilities: test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal failures, value-parameterised tests, type-parameterised tests, various options for running tests, and XML test report generation. Documentation now lives on GitHub Pages at google.github.io/googletest.

Version 1.18.0 was released on 10 August 2026. GoogleTest follows Google’s “live at head” philosophy: Google itself builds against the latest commit, and the project recommends updating regularly. Each release documents the minimum C++ standard required; recent versions require at least C++17 (see the README for the exact policy for your version).

GoogleMock adds a mocking framework for C++: define a mock class with MOCK_METHOD, set expectations with EXPECT_CALL, and use matchers and actions to describe arguments and return values. That makes it possible to test classes in isolation behind interfaces, which is otherwise awkward in C++.

How it compares: Catch2 and doctest favour a lighter, header-friendly style with natural boolean assertions and sections, while GoogleTest offers a larger, more structured feature set and the most mature C++ mocking library. CppUTest and Unity target embedded C and C++ with smaller footprints. GoogleTest’s CMake integration (FetchContent and gtest_discover_tests) and Bazel support make it easy to add to modern build systems, and IDEs such as CLion, Visual Studio and VS Code recognise its tests.

In the quality loop, GoogleTest covers unit and component tests for C++ libraries and services, and its XML output feeds CI dashboards; coverage is usually collected with gcov or llvm-cov and reported through tools such as gcovr.

The source code is at google/googletest on GitHub under the BSD-3-Clause licence, with about 39,700 stars; the most recent commit was on 11 November 2026.

Its README lists notable users beyond Google’s internal projects: the Chromium projects (behind the Chrome browser and ChromeOS), the LLVM compiler, Protocol Buffers and the OpenCV computer vision library. It also points to related open-source projects, including gtest-parallel, a runner that executes test binaries in parallel, the Qt-based GTest Runner GUI, and a TAP listener that emits Test Anything Protocol output.

Features

  1. Assertions: EXPECT_* (non-fatal) and ASSERT_* (fatal) macros for equality, comparisons, strings, floating point and exceptions.
  2. Test fixtures: TEST_F with SetUp and TearDown for shared state, plus suite-level setup.
  3. Parameterised tests: Value-parameterised (TEST_P) and type-parameterised tests run the same logic over many inputs or types.
  4. Death tests: Verify that code aborts or exits as expected under invalid conditions.
  5. GoogleMock: MOCK_METHOD, EXPECT_CALL, matchers and actions for C++ test doubles.
  6. Filtering and repetition: --gtest_filter, --gtest_repeat and --gtest_shuffle help isolate and flush out flaky tests.
  7. XML and JSON reports: Machine-readable output for CI systems.
  8. Build integration: CMake and Bazel support, including gtest_discover_tests for CTest.

Pros

  1. Complete package: Tests and mocks from one project and one dependency.
  2. Battle-tested: Used across Google and much of the C++ industry.
  3. Free to use: Open source under the BSD-3-Clause licence, so the core tool costs nothing to use.
  4. Actively maintained: The repository had commits as recent as 11 November 2026.
  5. Community: About 39,700 GitHub stars.

Cons

  1. Macro-heavy: Test code relies on macros, which some developers find noisy.
  2. Build integration effort: Adding it to legacy build systems can take work.
  3. Live-at-head expectations: Older compilers and C++ standards lose support over time.
  4. Compile times: Large test suites with many templates and mocks can slow builds.

Add GoogleTest with CMake FetchContent:

include(FetchContent)
FetchContent_Declare(googletest
  URL https://github.com/google/googletest/archive/refs/tags/v1.18.0.zip)
FetchContent_MakeAvailable(googletest)

enable_testing()
add_executable(price_test price_test.cc)
target_link_libraries(price_test GTest::gtest_main GTest::gmock)
include(GoogleTest)
gtest_discover_tests(price_test)

A test with a fixture and a mock:

#include <gmock/gmock.h>
#include <gtest/gtest.h>

class MockGateway : public Gateway {
 public:
  MOCK_METHOD(bool, Charge, (const std::string& user, int cents), (override));
};

TEST(CheckoutTest, ChargesTheUser) {
  MockGateway gateway;
  EXPECT_CALL(gateway, Charge("ana", 4200)).WillOnce(testing::Return(true));
  Checkout checkout(&gateway);
  EXPECT_TRUE(checkout.Pay("ana", 4200));
}

Run with CTest or directly:

ctest --output-on-failure
./price_test --gtest_filter=CheckoutTest.* --gtest_shuffle

Practical tips:

  1. Use EXPECT_* by default so one test reports several failures; use ASSERT_* when continuing makes no sense.
  2. Shuffle and repeat in CI occasionally to expose order-dependent tests.
  3. Keep mocks for true boundaries (I/O, clocks, networks) and test pure logic directly.

Resources:

Pricing

GoogleTest is free and open source under the BSD-3-Clause licence.

  1. C++ teams wanting a complete, well-documented test and mock framework.
  2. Projects using CMake or Bazel, where integration is straightforward.
  3. Large codebases needing parameterised and typed tests.
  4. Not a fit for very small embedded targets; consider Unity or CppUTest.

Conclusion

GoogleTest, together with GoogleMock, is the most complete and widely adopted testing toolkit for C++.

Its macros take some getting used to, but its assertions, fixtures, parameterised tests and mocking cover nearly every C++ testing need.

Compare

CheckOps pages that put GoogleTest next to related tools. There is no paid placement on these lists.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with GoogleTest side by side.