8
votes

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.

3
Which build system are you using? I don't know about CLion, but most build systems allow to define a custom target that depends on others. You could define a custom target run-all-tests depending on run-each-test. - Antonio Pérez
This is a CMake question, it is completely independent from CLion: if you fix it in CMakeLists.txt, the fix will work both with and without CLion. - marco.m
You're supposed to have a single main function in a googletest test suite. Why do you want to fight it? - Mike Kinghan
why don't you add the targets to ctest? - Nicolas Holthaus

3 Answers

2
votes

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.
0
votes

Cmake already generates a target to run all tests, run make test.

In Clion add a configuration that runs make test

0
votes

In CLion, navigate to Run > Edit Configurations...

Above the left-hand panel, click the plus (+) icon, and select Google Test.

To the right, set the Name field to something descriptive.

Set the Target field to the CMake project name whose unit tests you wish to run. If the target you're looking for isn't listed, you'll have to check to make sure your CMakeLists.txt file is configured correctly.

Once you click the OK or Apply button, this will be listed among your run configurations, and will run all unit tests for the executable you wish to test.