开发者

QTestlib unit testing project to access the classes in the main project within QTCreator

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 a main_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 using include($$PWD/main_project.pri)
  • Create a test project in your main_project folder.
  • In 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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜