I want to organize tests for a project large enough that build time matters (especially for the CI server).
Say I have this code that I would like to test :
//foo/greet.cpp
#include <stdio.h>
#include "foo/greet.h"
int greet() { return printf("Hello, World!\n"); }
And I have this main program that is boilerplate that I will not test.
//main.cpp
#include "foo/greet.h"
int main() { return greet(); }
I will use this code to generate a unittest program
//testgreet.cpp
#include <some_test_framework.h>
SOME_TEST_FRAMEWORK("Testing greet")
SOME_TEST_FRAMEWORK_ASSERT(greet() > 0)
SOME_TEST_FRAMEWORK_END()
I thought of the following
- Skipping the build of
greet.cpp
for the unittest target, and linking with the objects - Create a separate project structure for the tests, but share the output folder
- Pile everything in one place, maybe with a new folder named test
- Make a
greeting
library and link both main and unittests targets to it
How can I organize my project so that I can build greet.cpp
only once, yet reduce confusion caused by having two targets that share a lot of code ?
This question is related, but not duplicate (IMHO).
(+I tried making my question generic, reusable and future proof. If you think that this is too opinion based, vote to close and I will not repost)