C++ 的测试过程& Qt应用程序
我是一个主要用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试尽可能多地使用 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.
您很可能需要调整构建设置,以确保进行最小重建或增量构建,其中它仅编译已更改的文件,并且不会更新或重建未直接受更改影响的任何内容。当您更改在整个项目中大量包含的头文件时,这仍然没有帮助,但对于一个布局良好的项目来说,这是不应该发生的。
一般来说,有多种方法可以进行测试,但我建议主要有两件事:
当然,总是有一种像疯子一样充满信心地编码并在编译和运行时交叉手指的方法,这种方法很流行,但不太有效。
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:
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.
您的项目中是否有多个 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.
还回答了: 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/