Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a unit test project to an existing Qt Creator project

I have an existing Qt Creator project which is not a Subdirs project. I have now reached a point where I want to add a unit test project to it. When I create the new unit test project, the "Add as a subproject to..." combo is disabled.

How can I do it? I'm thinking about creating a brand new Subdirs project and adding my existing project to it, and then adding the unit test project as well.

Is that how it should be done or is there a better way?

like image 919
sashoalm Avatar asked Dec 10 '16 12:12

sashoalm


1 Answers

It's not a problem to change the project type to a subdir project (even for a gui app). That's the only way to add a unit test sub project to it. Steps:

  1. As mentioned, make your project a subdir project:

    TEMPLATE = subdirs

    SUBDIRS = gui logic

  2. Select File > New file or project ... > Other Project > Qt Unit Test

  3. At the last page "summary" of the wizard, select your project for "Add as a subproject to project"
  4. Your .pro file will be updated as follows:

    SUBDIRS = gui logic tests

Note: If you're manually restructuring the project hierarchy, make sure the name of the sub directory matches the name of .pro file within that sub directory.

For example:

  • sub directory name = test --> pro file name = test.pro
  • sub directory name = src --> pro file name = src.pro
like image 63
DrumM Avatar answered Sep 30 '22 10:09

DrumM