Tobias Wollgam
Tobias Wollgam

Reputation: 789

kdevelop Unit-Tests with gtest

I have a gtest cmake project that can be compiled and debugged with kdevelop. Since version 4.5 kdevelop can handle unit tests. I do not find a way to integrate the tests to kdevelop "Unit-Tests". Does anybody know how to do it?

Upvotes: 3

Views: 937

Answers (1)

FloWil
FloWil

Reputation: 442

For test binaries to show up in the Unit-Tests tab in Kdevelop (tested on 5.3) you need to make your testcases be recognized by CTest. If you have a dedicated CMakeLists.txt for your test-executable a minimal configuration could look like this:

set (SOURCES
  testsource.cpp
)

add_executable(testexecutable ${SOURCES})

target_link_libraries(testexecutable
  gtest
)

add_test(
  NAME test
  COMMAND testexecutable )

Additionally for it to be working with a standard CMake configuration run you need to add

enable_testing()

somewhere in your CMake project, eg. your main CMake file.

I found further documentation here: https://cmake.org/cmake/help/latest/command/add_test.html https://gitlab.kitware.com/cmake/community/wikis/doc/ctest/Testing-With-CTest

Be aware that this only adds basic execution of the testcase binaries to the KDevelop GUI. There is no customisation or/filtering in the GUI that I know of.

You may also have a look at the gtest specific defintions for cmake/ctest. I didn't try any of these as I'm stuck on a CMake version which does not support these yet. https://blog.kitware.com/dynamic-google-test-discovery-in-cmake-3-10/

Upvotes: 2

Related Questions