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

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