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:
- Move most of your config from
main_project.pro
file to amain_project.pri
file. - Use relative paths, relative to you *.pri or *.pro files, using
$$PWD/path/to/file
syntax where$$PWD
is your *.pri or *.pro file location. - Include
*.pri
file usinginclude($$PWD/main_project.pri)
- Create a
test
project in yourmain_project
folder. - In
test/test.pro
, add the lineinclude($$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...
精彩评论