I am using QT Creator and want to run my unit tests in a separate project. How do I reference the classes in the main project from my test project?
I realise this is an old question, but here are a few steps to make this easy:
main_project.pro
file to a main_project.pri
file.$$PWD/path/to/file
syntax where $$PWD
is your *.pri or *.pro file location.*.pri
file using include($$PWD/main_project.pri)
test
project in your main_project
folder.test/test.pro
, add the line include($$PWD/../main_project.pri)
to import the relevant configuration from you main_project.I can add more details if there is some interest.
Once the basic setup is working, it's quite handy as you can create a separate project for each module you want to test plus global test_suite that run all the other tests. If you find that many test projects share some configuration, you can create a separate common.pri
file in test/common
to include in all your test projects.
Once, that's in place, it quite easy to generate a small script to automatically create a test project when in order to test a new module, resulting quite an efficient testing workflow...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With