This is an example to use GTest
make new directory to project
.
├── build/
├── ext/
├── include/
├── src/
├── .gitignore
├── CMakeLists.txt
└── README.md
Go to ext/ directory and clone GTest
cd ext
git clone --depth=1 https://github.com/google/googletest.git
Use this CMakeLists.txt template
cmake_minimum_required(VERSION 3.5)
project(modio)
set (CMAKE_CXX_STANDARD 11)
IF( test AND test STREQUAL "on" )
message("Testing enabled")
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
add_subdirectory(ext/googletest)
enable_testing()
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(runUnitTests ${TEST_SRC_FILES})
target_link_libraries(runUnitTests gtest gtest_main)
add_test(UnitTests runUnitTests)
ENDIF()
Build project
cd build
cmake .. -Dtest=on
make -j18
Run test
make test
Run verbose test
ctest --verbose
Thanks to Ahmed Castro (https://youtu.be/-kQQX9UB21c?si=3Ju_ctXftOzYV1qW)