Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Unit Tests with Multiple Main in CLion with CMake

everyone.

In my specific Clion project, I have several cpp Unit Tests files (google tests), each of them with its main. I'm searching a way to run all unit tests of the project in a easy way. In this moment, I'm only able to run each target separately and I don't want to create a unique main for all tests.

OBS: The cpp unit test files is organizing in different folders inside of a "tests" folder.

How can anyone help me?

Note that CLion simply uses CMake to drive the build.

like image 960
Luckeciano Melo Avatar asked Apr 04 '16 23:04

Luckeciano Melo


People also ask

How do I add Google test to clion?

Adding Google Test to your project txt file inside the Google_tests folder: right-click it in the project tree and select New | CMakeLists. txt. In your root CMakeLists. txt script, add the add_subdirectory(Google_tests) command to the end, then reload the project.


1 Answers

The issue the OP referred to is that there are multiple targets that incorporate the binaries. The Google Test control only allows a single target. The answer is to use Compound execution.

First, review this concept, if unfamiliar: https://www.jetbrains.com/help/clion/creating-and-editing-run-debug-configurations.html

Second, follow these steps:

Steps:

  1. Create individual GTest test configurations for each test executable you want to include. https://www.jetbrains.com/help/clion/run-debug-configuration-google-test.html
  2. Create a compound execution configuration and add the individual executions created in step 1). https://www.jetbrains.com/help/clion/run-debug-configuration-compound-run-configuration.html
  3. Execute the new compound configuration from the run menu.
  4. To get a unified view of results, enable run dashboard when asked by pop-up prompt https://www.jetbrains.com/help/clion/creating-and-editing-run-debug-configurations.html
  5. You may consider sharing your execution spec with other users.
like image 88
Jörn Guy Süß Avatar answered Sep 20 '22 12:09

Jörn Guy Süß