C++ 的测试过程& Qt应用程序

发布于 2024-10-27 10:46:53 字数 204 浏览 6 评论 0原文

我是一个主要用 Qt 编写的大型(有点......)C++ 应用程序的一部分。 我想知道这是否是正确/常见的方法: 每当我对某个/多个源文件进行更改时,我都会在调试模式下编译它(QtCreator),然后启动并测试它。 问题是,每次编译都需要几分钟(通常是 1 - 3 分钟),我讨厌这样,而且我想我在这里做错了什么,也许为每个微小的更改编译整个项目并不是正确的路径去?

谢谢,

I'm a part of a big (sort of...) C++ application written mainly in Qt.
I was wondering if this is the right / common approach:
whenever I make a change to a certain / several source files, I compile it (QtCreator) in debug mode, and then launch and test it.
the problem is, each compilation takes a couple of minutes (usually a 1 - 3 minutes), I hate that, and I guess I'm doing something wrong here, maybe compiling the whole project for each minor change is not the right path to go?

thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鹿港小镇 2024-11-03 10:46:53

尝试尽可能多地使用 QTest 进行单元测试,然后您可以首先验证各个部分,然后对整个应用程序进行一些测试。这可以节省大量时间,如果做得正确,还可以帮助生成更健壮的代码。

这确实需要某种模块化方法,因此需要以某种方式对代码进行分组。

Try to use unit test with QTest as much as possible, then you can verify the parts first and then top it of with some test on the complete application. This saves a lot of time and can also help to produce more robust code if done right.

This do need some kind of modular approach, so the code needs to be grouped in some way.

玩物 2024-11-03 10:46:53

您很可能需要调整构建设置,以确保进行最小重建或增量构建,其中它仅编译已更改的文件,并且不会更新或重建未直接受更改影响的任何内容。当您更改在整个项目中大量包含的头文件时,这仍然没有帮助,但对于一个布局良好的项目来说,这是不应该发生的。

一般来说,有多种方法可以进行测试,但我建议主要有两件事:

  1. 不要重建整个项目(不清理,不重新构建所有项目),只需进行增量构建并进行测试。非常适合测试 GUI 更改以及不需要链接一百万个东西或启动时间较长的项目中的小东西。
  2. 使用控制台应用程序或简单的测试应用程序将其开发为单独的项目,您不会将其包含在最终的集成版本中,但可以保留以供以后进行独立测试。这对于库来说更好,比如您正在制作新的加密算法或文件管理器来替换更大项目的一些旧的过时部分。

当然,总是有一种像疯子一样充满信心地编码并在编译和运行时交叉手指的方法,这种方法很流行,但不太有效。

Most likely you need to tweak your build settings to ensure you are doing minimal rebuild or incremental build where it only compiles the files that have changed and doesn't update or rebuild anything not directly affected by the changes. This still doesn't help when you are changing a header file that's included heavily throughout the project but with a well laid out project that shouldn't happen.

In general there are several approaches to testing as you go but here are the main two things I'd recommend:

  1. Don't rebuild the entire project (no clean, no rebuid all) just do an incremental build and test as you go. Great for testing gui changes and little things in projects that don't need to link against a million things or have a long start up.
  2. Develop it as separate project with a console app or simple test application which you don't include in the final integrated version but can keep for independent testing later. This is better for libraries like say you are making a new encryption algorithm or file manager to replace some old archaic portion of a bigger project.

Of course there is always the approach of coding with overwhelming confidence like a crazy person and crossing your fingers when you compile and run it which is very popular but not quite as effective.

鲜肉鲜肉永远不皱 2024-11-03 10:46:53

您的项目中是否有多个 SUBDIRS 目标?如果答案是肯定的,您可以尝试调整项目文件,首先从项目文件中删除所有“有序”关键字,然后如果一个子目录依赖于另一个子目录,则将它们声明为依赖项。最后,确保将 -jX 值传递给 make(即,如果您的构建规则使用 make),以便在编译时使用所有 cpu 核心。

Do you have multiple SUBDIRS targets within your project ? If the answer is yes, You could try tweaking the project file by first removing all "ordered" keywords from project files and then if one subdir is depending on another, declare those as dependencies. And finally, make sure you pass -jX value to make (that is, if your build rules use make) so that all cpu cores are taken into use while compiling.

无敌元气妹 2024-11-03 10:46:53

还回答了: Qt 自动化测试

我和我的团队最近开发了 TUG,一个开放的-Qt GUI 单元测试的源框架。是使用Qt Test。也许它可以帮助你。

一个视频胜过千言万语:
https://www.youtube.com/watch?v=tUis6JrycrA

希望我们可以一起让它变得更好。 Github 仓库:http://pedromateo.github.io/tug_qt_unit_testing_fw/

Also answered in: Qt automated testing

I along with my team recently developed TUG, an open-source framework for Qt GUIs Unit Testing. Is uses Qt Test. Maybe it can help you.

A video better than a thousand words:
https://www.youtube.com/watch?v=tUis6JrycrA

Hope we can make it better together. Github repo: http://pedromateo.github.io/tug_qt_unit_testing_fw/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文