10.04-CTEST-GTest

CTest和Gtest

参考

CMake/Testing With CTest
cmake结合CTest的例子

前言

  • 在VSCode中配合CMakeTools工具使用这个测试框架,还比较方便

学习过程

CDash环境搭建(没完成)

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 

简介

CTest是CMake的一部分,是一个测试框架,可以将构建,配置,测试,覆盖率等指标更新到CDash看板工具上。
有两种模式:

  • 一种是,在CMakeLists.txt中创建和执行测试
  • 一种是,运行脚本来执行整个测试流程,包括更新代码,配置和构建项目
    这次我们只学习第一种模式。

CMake中使用GTest

首先安装3.9版本的CMake

因为要用到cmake server

将gtest-1.8.0添加到项目路径下

几个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>
   )

猜你喜欢

转载自www.cnblogs.com/lizhensheng/p/11117295.html