GoogleTest 与 CppUnit:事实
在为未来几年设置 C++ 单元测试框架的过程中,我们入围了 GoogleTest 和 CppUnit。我对两者都有一些经验,我最喜欢的是 GoogleTest。无论如何,为了说服我的老板,我需要一些事实,所以我在互联网上阅读了一些内容,包括手册、维基页面和一些来源。我列出了 GoogleTest 优势和单个 CppUnit 优势(图形测试运行程序)。这里它们按感知有用性排序:
- INSTANTIATE_TEST_CASE_P 使用您想要的任何参数集实例化测试用例,包括笛卡尔积
- FRIEND_TEST 用于测试私有类成员(对于所有遗留代码)
- 将断言转换
- 为非 断点-fatal 断言
- “开箱即用”googlemock 集成
- 自动测试检测,无需枚举它们
- 可以禁用测试并
- 可以选择启用要运行的测试名称模式
- 值/类型参数化测试
- 用户定义谓词断言
- 死亡测试
- 更丰富的断言集
- 类型断言
- 在子例程上断言
- 可以使用 << 将附加调试信息添加到断言中
- RecordProperty 将属性的最后一个值发送到 XML 输出
- SCOPED_TRACE 有助于了解来自子例程或循环内部的断言失败的上下文。
- xUnit XML 输出,可以立即由 Jenkins 显示,无需在
- 支持自定义类型打印机
- 之间进行 XSLT 转换测试指示所消耗的时间(我怀疑这对于 CppUnit 也是可能的,但我还没有弄清楚)
- 测试事件侦听器 API(用户-定义的插件)
- 测试洗牌
- 没有例外和 RTTI
我假设 CppUnit 不支持以上所有内容是否正确?我在 CppUnit 中是否缺少一个不可用有用的 GoogleTest 功能?
最后但并非最不重要的一点是:GoogleTest 缺乏有哪些不错的 CppUnit 功能吗?
谢谢!
In the process of setting our C++ unit testing framework for the next years we shortlisted GoogleTest and CppUnit. I have some experience with both and my heavy preference is GoogleTest. Anyways to convince my boss I need some facts so I did some reading on the Internet, including the manuals, wiki pages and some of the sources. I came up with a list of GoogleTest advantages and a single CppUnit advantage(graphic test runners). Here they are ordered by perceived usefulness:
- INSTANTIATE_TEST_CASE_P to instantiate a test case with any set of parameters you want, including Cartesian products
- FRIEND_TEST for testing private class members(for all the legacy code)
- turning asserts into breakpoints
- non-fatal asserts
- "out of the box" googlemock integration
- automatic tests detection, no need to enumerate them
- tests can be disabled and enabled
- tests to run can be selected using name patterns
- value/type-parameterized tests
- user-defined predicate asserts
- death tests
- much richer set of asserts
- type asserts
- asserting on subroutines
- additional debug info can be added to asserts using <<
- RecordProperty emits last value of property to the XML output
- SCOPED_TRACE helps understand the context of an assertion failure coming from inside a sub-routine or loop.
- xUnit XML output, can be shown by Jenkins right away without a XSLT transformation in between
- supports custom types printers
- time consumed by test indication(I suspect this is also possible with CppUnit but I haven figured it out yet)
- test event listener API (user-defined plug-ins)
- test shuffling
- no exceptions and RTTI
Am I correct in assuming that all of the above are not supported by CppUnit? Is there an useful GoogleTest feature not available in CppUnit I am missing?
And last but not least: Are there any nice CppUnit features that GoogleTest lacks?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用旧版本的 gcc 编译器,或者您的测试代码在 vxWorks(或 VxSim)上运行,您可能会比 Googletest 框架更有机会使用 cppUnit。
另一方面,googletest 框架的另一个功能是 3 个不同级别的设置/拆卸的可用性:
不确定 cppUnit 是否支持这一点,但这可能会非常重要。方便,尤其是对于遗留系统。
另外,还有一个用于 Eclipse CDT 的 googletest 插件。
If you use older version of gcc compiler or if your code under tests runs on vxWorks (or VxSim) you might have a better chance with cppUnit than Googletest framework.
On the other hand, another feature of the googletest framework is availability of 3 different levels of setup/teardown:
Not sure if this is supported in cppUnit, but this might come very handy, especially with legacy systems.
Also, there is a googletest plugin for Eclipse CDT.
如果您还没有看过 xUnit++,我特意制作了它,因为我对可用的内容不满意(包括 gtest)。您列表中的大部分功能都受支持,如果没有,如果它是“必须具备”的功能,我可能愿意添加它。
If you haven't looked at xUnit++, I made it specifically because I was unhappy with what was available (including gtest). Most of your list is supported, and if not, if it's a "must have" feature, I'd probably be willing to add it.
这些是我看到的好处。有几个 GUI 测试运行程序:
我用过这第一个,它运行得很好,尽管它正在开发中并且需要一些工作。不知道是否还有其他选择。
Those are the benefits I see. There are a couple of GUI test runners:
I have used the first one and it works pretty well although it's in development and needs some work. Don't know if there are other options.