Organizing multi library cmake target with gtests

120 Views Asked by At

I am starting to introduce googletests to our multi-library production codebase and I would like some advice on how to organize better my tests.

We have many internal libraries that we compile as a grand library that executables link against. The structure let's say is something like:

├──LIB_A
|   ├──CMakeLists.txt
|   ├──src/
|   └──include/
├──LIB_B
|   ├──CMakeLists.txt
|   ├──src/
|   └──include/
...
├──LIB_Z
|   ├──CMakeLists.txt
|   ├──src/
|   └──include/
└──CMakeLists.txt

The last CMakeLists will add_subdirectory() the libraries and produce the Grand Library.

In this structure I would like to introduce tests. Most tests I am thinking of, are to test each library rather than the whole thing. I have been advised by a colleague that tests should be introduced to the Grand Library level and not inside each library. To make it graphic, what would be best?

A:

├──LIB_A
|   ├──CMakeLists.txt
|   ├──src/
|   ├──include/
|   └──tests/
├──LIB_B
|   ├──CMakeLists.txt
|   ├──src/
|   ├──include/
|   └──tests/
...
├──LIB_Z
|   ├──CMakeLists.txt
|   ├──src/
|   ├──include/
|   └──tests/
└──CMakeLists.txt

OR B:

├──LIB_A
|   ├──CMakeLists.txt
|   ├──src/
|   └──include/
├──LIB_B
|   ├──CMakeLists.txt
|   ├──src/
|   └──include/
...
├──LIB_Z
|   ├──CMakeLists.txt
|   ├──src/
|   └──include/
├──tests/
└──CMakeLists.txt
1

There are 1 best solutions below

0
KamilCuk On

what would be best?

Both.

├──LIB_A
|   ├──tests/  <- unit tests of LIB_A components
               \- and integration tests of LIB_A with dependent components

├──tests/      <- integration tests between all components
               \- functional tests of the whole system