I am using Qt Creator with qmake to create my project and my test project (QTest-tests). I have the test project running on its own now, but I have a hard time to understand how to test classes from my normal project. I can include the .h files from my project in the test cases, but that’s of course not enough.
It throws my linker errors since it does have not the code or a library to look up the code for the class. Is there a simple way to tell qmake to look up all source files in a specific folder to load them? Or what is the correct way to set up such a test project without having to add each source file also to the test project or compiling your application into an library to include?
qmake supports wildcards so you can have something like
in your project file.
Also make sure to adjust
MOC_DIRandRCC_DIRto point somewhere else than the source folder. You don’t want to include generated source files in yourSOURCES.I prefer to separate my automated tests into two classes:
Unit tests testing single components (usually living in a source file). I mock away dependencies to other parts of the system. Each unit test is a Qt project of its own and only includes the source files being tested + test code + mock code.
Integration tests testing components as whole without mock code. Usually it’s the application engine part built as a library and then linked to the test project.