将单元测试项目添加到现有的 Qt Creator 项目 [英] Add a unit test project to an existing Qt Creator project

查看:57
本文介绍了将单元测试项目添加到现有的 Qt Creator 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的 Qt Creator 项目,它不是 Subdirs 项目.我现在已经到了要向其中添加单元测试项目的地步.当我创建新的单元测试项目时,作为子项目添加到..."组合被禁用.

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.

我该怎么做?我正在考虑创建一个全新的 Subdirs 项目并将我现有的项目添加到其中,然后再添加单元测试项目.

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?

推荐答案

将项目类型更改为子目录项目(即使对于 gui 应用程序)也不是问题.这是向其中添加单元测试子项目的唯一方法.步骤:

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. 如前所述,将您的项目设为子目录项目:

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

模板 = 子目录

SUBDIRS = gui 逻辑

SUBDIRS = gui logic

选择文件 > 新建文件或项目... > 其他项目 > Qt 单元测试

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

您的 .pro 文件将更新如下:

Your .pro file will be updated as follows:

SUBDIRS = gui 逻辑测试

SUBDIRS = gui logic tests

注意:如果您手动重构项目层次结构,请确保子目录的名称与该子目录中的 .pro 文件的名称匹配.

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.

例如:

  • 子目录名 = test --> pro 文件名 = test.pro
  • 子目录名 = src --> pro 文件名 = src.pro
  • sub directory name = test --> pro file name = test.pro
  • sub directory name = src --> pro file name = src.pro

这篇关于将单元测试项目添加到现有的 Qt Creator 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆