Issue
I have a small c++ project that I converted to cmake (from visual studio's native solutions), as this now appears to be industry standard.
However, there are appear to be some negative side effects: The boost tests are no longer discovered by visual studio's test explorer.
The projct is visible here: https://github.com/dickreuter/neuron_poker/tree/master/tools/montecarlo_cpp
It contains Test.cpp which contains some tests that should be discovered.
the cmake file looks as below. Could this be the issue or what could be the cause of the problem?
cmake_minimum_required(VERSION 3.15)
project(montecarlo_cpp)
set(CMAKE_CXX_STANDARD 14)
include_directories("C:/Users/dickr/Anaconda3/include" "C:/Users/dickr/git/vcpkg/installed/x64-windows/include" )
link_directories("C:/Users/dickr/Anaconda3/libs")
add_executable(montecarlo_cpp
Montecarlo.cpp
Montecarlo.h
Test.cpp)
TARGET_LINK_LIBRARIES( montecarlo_cpp LINK_PUBLIC ${Boost_LIBRARIES} )
Solution
Need to correctly configure tests discovering in the CMake file and tests will be shown in the Visual Studio Tests Explorer. Please follow instructions from Boost official page Boost Tests Frequently Asked Questions. I've modified your "CMakeLists.txt":
cmake_minimum_required(VERSION 3.15)
project(montecarlo_cpp)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
add_executable(${PROJECT_NAME}
Montecarlo.cpp
Montecarlo.h
Test.cpp)
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE Boost::unit_test_framework ${PYTHON_LIBRARY})
enable_testing()
add_test(NAME montecarlo_tests COMMAND ${PROJECT_NAME})
And tests has been successfully discovered by Visual Studio 2022 Tests Explorer:
Please also make sure that you are installed Test Adapter for Boost.Test, it is available since Visual Studio 2017 and can be installed via the Visual Studio Installer / Individual components.
Answered By - Pavel K. Answer Checked By - Robin (WPSolving Admin)