CTest and Gtest
reference
Testing With CTest CMake /
CMake Examples of binding CTest
Foreword
- VSCode with CMakeTools tools used in this testing framework, but also more convenient
learning process
CDash environment to build (did not finish)
sudo apt install mysql-server mysql-client
sudo apt-get install apache2
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
sudo apt-get install php-cli php-curl php-gd php7.0-xsl
Brief introduction
CTest CMake is part of a test frame can be constructed, configure, test, and other indicators update to the coverage CDash Kanban tool.
There are two modes:
- One is to create and execute tests in CMakeLists.txt
- One is, run a script to perform the entire testing process, including updating the code, configure and build the project
this time we only learn the first model.
CMake use GTest
First, install the 3.9 version of CMake
Because to use cmake server
Add the gtest-1.8.0 path to the project
Several CMakeLists.txt
- top level cmakelists
cmake_minimum_required(VERSION 2.8.3)
project(apue)
# using cmaktools in vscode
include(CMakeToolsHelpers OPTIONAL)
# set output path
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# set cpp standard
#SET(CMAKE_CXX_FLAGS "-std=c++11")
# set before finding packages
list(APPEND CMAKE_MODULE_PATH ./cmake)
# find packages
# include dirs
include_directories(
/usr/include
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/lib
)
# add subdirectories
add_subdirectory("./include")
add_subdirectory("./lib")
add_subdirectory("src/hello_world")
# add executable
# CTest
if(NOT without-test)
enable_testing()
include(CTest)
add_subdirectory("./gtest-1.8.0")
endif()
- test folder cmakelists
# add executable
add_executable(hello_world hello_world.cpp)
target_link_libraries(hello_world apue)
# CTest
enable_testing()
add_executable(hello_world_test hello_world_test.cpp)
target_link_libraries(hello_world_test
gtest
gtest_main
pthread
apue
)
add_test(
NAME apue
COMMAND $<TARGET_FILE:hello_world_test>
)