我应该为 Qt 使用什么单元测试框架? [英] What unit-testing framework should I use for Qt?

查看:22
本文介绍了我应该为 Qt 使用什么单元测试框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始一个需要一些跨平台 GUI 的新项目,我们选择了 Qt 作为 GUI 框架.

I am just starting up a new project that needs some cross-platform GUI, and we have chosen Qt as the GUI-framework.

我们也需要一个单元测试框架.直到大约一年前,我们还在为 C++ 项目使用内部开发的单元测试框架,但现在我们正在过渡到在新项目中使用 Google 测试.

We need a unit-testing framework, too. Until about a year ago we used an in-house developed unit-testing framework for C++-projects, but we are now transitioning to using Google Test for new projects.

有没有人有将 Google Test 用于 Qt 应用程序的经验?QtTest/QTestLib 是更好的选择吗?

Does anyone have any experience with using Google Test for Qt-applications? Is QtTest/QTestLib a better alternative?

我仍然不确定我们希望在项目的非 GUI 部分中使用 Qt 的程度 - 我们可能更愿意在核心代码中使用 STL/Boost,并为基于 Qt 的 GUI 提供一个小接口.

I am still not sure how much we want to use Qt in the non-GUI parts of the project - we would probably prefer to just use STL/Boost in the core-code with a small interface to the Qt-based GUI.

看起来很多人都倾向于 QtTest.有没有人有将它与连续集成服务器集成的经验?此外,在我看来,必须为每个新测试用例处理一个单独的应用程序会导致很多摩擦.有什么好的方法可以解决吗?Qt Creator 是否有处理此类测试用例的好方法,或者您是否需要每个测试用例都有一个项目?

It looks like many are leaning towards QtTest. Is there anybody who has any experience with integrating this with a continous integration server? Also, it would seem to me that having to handle a separate application for each new test case would cause a lot of friction. Is there any good way to solve that? Does Qt Creator have a good way of handling such test cases or would you need to have a project per test case?

推荐答案

我不知道 QTestLib 在这种笼统的意义上比一个框架更好"于另一个框架.有一件事它做得很好,这提供了一种测试基于 Qt 的应用程序的好方法.

I don't know that QTestLib is "better" than one framework for another in such general terms. There is one thing that it does well, and that's provide a good way to test Qt based applications.

您可以将 QTest 集成到基于 Google 测试的新设置中.我没试过,但根据 QTestLib 的架构,似乎不会太复杂.

You could integrate QTest into your new Google Test based setup. I haven't tried it, but based on how QTestLib is architected, it seems like it would not be too complicated.

使用纯 QTestLib 编写的测试具有您可以使用的 -xml 选项,以及一些 XSLT 转换以转换为持续集成服务器所需的格式.但是,这很大程度上取决于您使用的 CI 服务器.我想这同样适用于 GTest.

Tests written with pure QTestLib have an -xml option that you could use, along with some XSLT transformations to convert to the needed format for a continuous integration server. However, a lot of that depends on which CI server you go with. I would imagine the same applies to GTest.

每个测试用例一个单独的测试应用程序从来没有给我带来很多摩擦,但这取决于有一个构建系统能够很好地管理测试用例的构建和执行.

A single test app per test case never caused a lot of friction for me, but that depends on having a build system that would do a decent job of managing the building and execution of the test cases.

我不知道 Qt Creator 中的任何内容需要每个测试用例有一个单独的项目,但自从我上次查看 Qt Creator 以来,它可能已经改变.

I don't know of anything in Qt Creator that would require a seperate project per test case but it could have changed since the last time I looked at Qt Creator.

我还建议坚持使用 QtCore 并远离 STL.始终使用 QtCore 将使处理需要 Qt 数据类型的 GUI 位更容易.在这种情况下,您不必担心从一种数据类型转换为另一种数据类型.

I would also suggest sticking with QtCore and staying away from the STL. Using QtCore throughout will make dealing with the GUI bits that require the Qt data types easier. You won't have to worry about converting from one data type to another in that case.

这篇关于我应该为 Qt 使用什么单元测试框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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