# Folder structurefor tests in project and in library

**URL:** <https://discourse.cmake.org/t/folder-structurefor-tests-in-project-and-in-library/7732>\
**Category:** Code\
**Created:** [March 21, 2023, 11:13am UTC](https://discourse.cmake.org/t/folder-structurefor-tests-in-project-and-in-library/7732 "2023-03-21T11:13:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bertrand\_Thelen](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bertrand_thelen/32/3277_2.png) [@Bertrand\_Thelen](https://discourse.cmake.org/u/Bertrand_Thelen)\
**Post date:** [March 21, 2023, 11:13am UTC](https://discourse.cmake.org/t/folder-structurefor-tests-in-project-and-in-library/7732/1 "2023-03-21T11:13:42Z")

</div>

Hi,

I’m rather new to cmake and I struggle a bit with my folders structure

The project is cross-compiled to arm but the tests runs on the host. I don’t think that the multi-arch setup is relevant for this question but I add it for context just in case.

So here is my current project structure

MyProject

- Src/  
main.cpp (main for the target)
- Inc/… (all headers)
- Test/… (all test\__.cpp)  
testMain.cpp (main for the host to discover and run the tests)  
– Mock/mock\__.h (all the mocks for the hardware abstraction between the host and the target)  
– thirdparty/  
doctest.h (test framework)  
tromploeil.h (mock framework)
- MyLib/ (static lib used by MyProject, MyOtherProject and others)  
– Src/  
– Inc/  
– Test… (all test\__.cpp)  
testMain.cpp (main for the host to discover and run the library tests)  
– Mock/mock\__.h (all the mocks needed to test the library)  
– thirdparty/  
doctest.h (test framework)  
tromploeil.h (mock framework)

So my issue is that the test framework (Test/thirdparty) is duplicated in each project and in the library.  
That makes MyLib independant from the projects using it so it seems good from that perspective but it seems a bit redundant.

And I have the additionnal probem that the mocks from the MyLib/Test/Mock folder are sometimes usefull for the tests of the projects as well.

I would like to be able to run the tests of the project only from my ide. But, for theCI builds, I would like to perform the full test suite (MyProject tests + MyLib tests)

What are the recommended/best practices for such setups?

---

<div class="post-metadata">

**Author:** ![assignUser](https://discourse.cmake.org/user_avatar/discourse.cmake.org/assignuser/32/3367_2.png) [@assignUser](https://discourse.cmake.org/u/assignUser)\
**Post date:** [April 21, 2023, 11:58pm UTC](https://discourse.cmake.org/t/folder-structurefor-tests-in-project-and-in-library/7732/2 "2023-04-21T23:58:51Z")

</div>

Hi!

Is this the on disk structure or in the repo? I assume repo and you are adding MyLib as a git submodule but vendoring Test/thirdparty in every project? Easy answer to reduce duplication would be to use thirdparty as a submodule too. Or use FetchContent to get thridparty and MyLib?

For the mocks: if there is a core et of mocks that are useful cross-project why not create a header only lib to modularize and share them?
