Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Tests in CLion using CMake's CTest

I have a C++ project using CMake. The project is built on CentOS machine. I have configured CLion to build remotely from MacOS. I have unit tests for the project and I am trying to run them from CLion. I can run the tests from CentOS machine using CTest like below

ctest -r utCppProject -v

CLion tries to run the executable directly with gtest flags like below

./utCppProject --gtest_filter=* --gtest_color=no
Process finished with exit code 0

No tests are actually run.

How can I configure CLion to be able to use CTest for running unit tests?

Here is my CMakeLists.txt for the unit test project

cmake_minimum_required(VERSION 3.4.1)

include(../../cmake-dependencies/Boost.cmake)
include(../../cmake-dependencies/GoogleTest.cmake)

set(CMAKE_BINARY_DIR "${CMAKE_CURRENT_LIST_DIR}/../build")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)


include_directories(${GOOGLE_TEST_DIR}/googletest/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)


set(TARGET utCppProject)

add_executable (
   ${TARGET}
   utCppProject.cpp
)

target_link_libraries (
    ${TARGET}
    CppProject
    gtest
    boost_system
    pthread
)

set(CMAKE_CXX_FLAGS "-fPIC -DPIC -Wall -Werror -std=c++0x")

set(TEST_OUTPUT "${CMAKE_BINARY_DIR}/test_results/${TARGET}.xml")
add_test(${TARGET} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET})
set_tests_properties(${TARGET} PROPERTIES
  ENVIRONMENT 
  "UT_FOLDER_PATH=${CMAKE_CURRENT_SOURCE_DIR};GTEST_OUTPUT=xml:${TEST_OUTPUT}")
like image 590
adsun Avatar asked Sep 26 '19 20:09

adsun


1 Answers

Since CLion 2020.3 EAP CTest is supported from the box.

like image 165
uta Avatar answered Oct 11 '22 09:10

uta