Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 903
odie Avatar asked Nov 04 '22 20:11

odie


1 Answers

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...

like image 108
AntonyG Avatar answered Dec 06 '22 08:12

AntonyG