使用 cxxtest 框架和 valgrind 测试 qt 对象

发布于 2024-10-04 01:35:52 字数 303 浏览 0 评论 0原文

是否可以使用 cxxunit 或任何其他单元测试框架(不包括 QtTestLib) 来测试 qt 小部件?

如果是的话,那么还有两个问题:

  1. 如何?
  2. 由于我正在使用 valgrind 运行单元测试,这会报告一些错误吗?

Is it possible to use cxxunit or any other unit testing framework (excluding QtTestLib) to test qt widgets?

If yes, then there are two more questions :

  1. How?
  2. Since I am running unit tests using valgrind, can this report some errors?

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

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

发布评论

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

评论(2

噩梦成真你也成魔 2024-10-11 01:35:52

是的,这应该是可能的。我具体不确定 cxxunit,但理论上是可能的。

  1. 为了正确测试 Qt 对象,您可能需要在全局设置和拆卸函数中创建/销毁 QApplication 对象。除非您专门测试 QApplication 功能,否则您应该只为测试应用程序的整个运行创建一个。这将允许您测试小部件的部分逻辑,但不能轻松测试小部件的外观或 UI 交互性。此外,测试某些项目可能依赖于应用程序事件循环的运行,这会更加困难。
  2. Valgrind 可能会报告一些错误。它还可能报告 Qt 代码的错误,特别是留给应用程序拆卸以回收的静态分配。

Yes, it should be possible. I'm not sure about cxxunit specifically, but it is theoretically possible.

  1. To properly test Qt objects, you will probably need to create/destroy a QApplication object in your global setup and teardown functions. Unless you are specifically testing QApplication functionality, you should only create one for the entire run of the test application. This will allow you to test portions of the widget's logic, but not easily the appearance or UI interactivity of the widget. Also, testing certain items may rely on having the application's event loop running, which would be more difficult.
  2. Valgrind may report some errors. It may also report errors with Qt's code, in particular static allocations that are left to application teardown to reclaim.
时光暖心i 2024-10-11 01:35:52

如果你想测试你的 UI,我建议使用 UI 测试工具,比如 Squish。我发现单元测试更适合测试小部件背后的逻辑,而不是小部件本身。如果您确实想对 Qt 小部件进行单元测试,我认为没有比 QtTestLib 更好的解决方案了。

Valgrind:有一个 Squish 的 valgrind 插件。不过我自己还没用过那个。其他单元测试当然可以轻松地在 valgrind 中运行,尽管我不知道有任何解决方案可以完全自动化此操作。人们必须确保真正抑制来自外部代码的所有警告,以便 x11 库中的某些错误不会触发单元测试失败。

If you want to test your UI, I suggest to use a UI testing tool like Squish. Unit tests I find more suited to test the logic behind the widgets, not the widgets itself. If you really want to unit-test your Qt widgets, I don't think there is a better solution than QtTestLib.

Valgrind: There is a valgrind plugin for Squish. I haven't used that one myself though. Other unit tests can of course easily be run in valgrind, although I don't know of any solution that fully automates this. One would have to make sure to really suppress all warnings from outside one owns code so that some error in e.g. x11 libs doesn't trigger the unit test to fail.

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