For the complete documentation index, see llms.txt. This page is also available as Markdown.

GTest

Installation in Ubuntu

sudo apt install libgtest-dev

Usage in CMake

# gtest
find_package(GTest REQUIRED)  # GTestConfig.cmake available
include_directories(${GTEST_INCLUDE_DIRS})

add_executable (main src/main.cpp)
target_link_libraries (main ${GTEST_BOTH_LIBRARIES})

# alternatively
include(GoogleTest) # for CMake version > 3.9

Tutorial

  • ASSERT_* versions generate fatal failures when they fail, and abort the current function.

  • EXPECT_* versions generate nonfatal failures, which don’t abort the current function.

  • Test results will show up when you run the GTest executable after compilation.

GMock

When you write a prototype or test, often it’s not feasible or wise to rely on real objects entirely. A mock object implements the same interface as a real object, but lets you specify at run time how it will be used and what it should do.

GMock has been merged into GTest project in 2019.

Last updated