将单元测试项目添加到现有的 Qt Creator 项目

编程入门 行业动态 更新时间:2024-10-26 02:31:25
本文介绍了将单元测试项目添加到现有的 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:

  • 如前所述,将您的项目设为子目录项目:

  • 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 项目

    本文发布于:2023-11-14 11:29:57,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1587093.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:项目   单元测试   Creator   Qt

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!