Before trying to do any unit testing, I had a directory like
mything.h
mything.cpp
mything2.h
mything2.cpp
driver.cpp // contains main()
Makefile
Then I would make
and run the produced executable; this executable was produced in the root directory (call it runme
).
Now I'm trying to use Catch2 https://github.com/catchorg/Catch2/blob/master/docs/Readme.md#top) which also says to have one testing file with a main (they have a define for it). So I reorganized my code as
src/
mything.h
mything.cpp
mything2.h
mything2.cpp
driver.cpp // contains main()
test/
catch2.hpp // downloaded off their website in single header option
sometest.cpp // also contains a main per catch2
Makefile
I made some dummy tests that don't reference my actual code. Now I do make tester
and ./tester
which runs all the tests. And I can do make
and ./runme
to run my original application.
My question now is, how do I actually call my source code from the test code? Do I need to convert this src
dir into a library? That is, how test code references src code in c++ is a bit unclear to me.
For full disclosure, I'm coming from the python/pytest world, and wondering how you actually structure c++ code w.r.t. unit testing or proper project structure.