Boost.Test-如何将测试套件(源码文件)组织成工程、并执行测试

Boost.Test资源及示例的续篇
1.测试套件TestSuite的源码文件组织如下图
Boost.Test-如何将测试套件(源码文件)组织成工程、并执行测试_第1张图片
Boost.Test-如何将测试套件(源码文件)组织成工程、并执行测试_第2张图片

2.CMakeLists.txt需要自己编写,本例内容如下

cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
project(mytestmodule)
enable_testing()

# indicates the location of the boost installation tree.
# hard-coded for our simple example.
set(BOOST_INCLUDE_DIRS "C:/Boost/include/boost-1_84/")
set(Boost_UNIT_TEST_FRAMEWORK_LIBRARY "C:/Boost/lib")

# replace XX with the version you have
set(Boost_ADDITIONAL_VERSIONS "1.84" "1.84.0")

# finds boost, triggers an error otherwise
# find_package(Boost XX REQUIRED COMPONENTS unit_test_framework)


# indicates the include paths
include_directories(${BOOST_INCLUDE_DIRS})

# indicates the shared library variant
#如果源码文件里已经定义,此处注释掉
#target_compile_definitions(test_executable PRIVATE "BOOST_TEST_DYN_LINK=1")

# indicates the link paths
link_directories(${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

# creates the executable
#此次 把需要拉近工程的测试套件源文件加入
add_executable(test_executable MyTestModule.cpp MyTestSuite1.cpp MyTestSuite2.cpp)

# declares a test with our executable
add_test(NAME MYTESTMODULE COMMAND test_executable)

3.执行生产、编译及测试,本例命令如下

>cmake -G " Visual Studio 14 2015 Win64" ../src

在这里插入图片描述

>ctest --build-config debug --output-on-failure

Boost.Test-如何将测试套件(源码文件)组织成工程、并执行测试_第3张图片

你可能感兴趣的:(Boost.Test)