C++ GoogleTest 与 CppUnit:事实
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7922289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GoogleTest vs CppUnit: The facts
提问by EstuansInterius
In the process of setting our C++ unit testing framework for the next years we shortlisted GoogleTestand CppUnit. I have some experience with both and my heavy preference is GoogleTest. Anyways to convince my boss I need some factsso 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 perceivedusefulness:
在为未来几年设置 C++ 单元测试框架的过程中,我们将GoogleTest和CppUnit列入了候选名单。我对两者都有一些经验,我最喜欢的是 GoogleTest。无论如何,为了说服我的老板,我需要一些事实,所以我在互联网上阅读了一些资料,包括手册、维基页面和一些来源。我想出了一个 GoogleTest 优势列表和一个 CppUnit 优势(图形测试运行器)。在这里,它们按感知的有用性排序:
- 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
- INSANTIATE_TEST_CASE_P 使用您想要的任何参数集实例化测试用例,包括笛卡尔积
- FRIEND_TEST 用于测试私有类成员(用于所有遗留代码)
- 将断言变成断点
- 非致命断言
- “开箱即用”的 googlemock 集成
- 自动测试检测,无需枚举
- 可以禁用和启用测试
- 可以使用名称模式选择要运行的测试
- 值/类型参数化测试
- 用户定义的谓词断言
- 死亡测试
- 更丰富的断言集
- 类型断言
- 在子程序上断言
- 可以使用 << 将额外的调试信息添加到断言中
- RecordProperty 将最后一个属性值发送到 XML 输出
- SCOPED_TRACE 有助于理解来自子例程或循环内部的断言失败的上下文。
- xUnit XML 输出,Jenkins 可以立即显示,中间没有 XSLT 转换
- 支持自定义类型打印机
- 测试指示消耗的时间(我怀疑 CppUnit 也可以这样做,但我还没有弄清楚)
- 测试事件监听 API(用户自定义插件)
- 测试洗牌
- 没有例外和 RTTI
Am I correct in assuming that all of the above are not supported by CppUnit? Is there an useful GoogleTest feature not availablein CppUnit I am missing?
假设 CppUnit 不支持上述所有内容,我是否正确?是否有一个有用的功能GoogleTest无法在CppUnit的我失踪?
And last but not least: Are there any nice CppUnit features that GoogleTest lacks?
最后但并非最不重要的一点:是否有 GoogleTest缺少的任何不错的 CppUnit 功能?
Thanks!
谢谢!
回答by ratkok
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.
如果您使用旧版本的 gcc 编译器,或者如果您的测试代码在 vxWorks(或 VxSim)上运行,您使用 cppUnit 的机会可能比 Googletest 框架更好。
On the other hand, another feature of the googletest framework is availability of 3 different levels of setup/teardown:
另一方面,googletest 框架的另一个功能是提供 3 个不同级别的设置/拆卸:
- per program
- per test case (or test group)
- per individual test instances
- 每个节目
- 每个测试用例(或测试组)
- 每个单独的测试实例
Not sure if this is supported in cppUnit, but this might come very handy, especially with legacy systems.
不确定 cppUnit 是否支持它,但这可能会非常方便,尤其是对于遗留系统。
Also, there is a googletest plugin for Eclipse CDT.
此外,还有一个用于 Eclipse CDT 的 googletest 插件。
回答by Brad W
Those are the benefits I see. There are a couple of GUI test runners:
这些是我看到的好处。有几个 GUI 测试运行程序:
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.
我已经使用了第一个,虽然它正在开发中并且需要一些工作,但它运行良好。不知道有没有其他选择。
回答by moswald
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.
如果您还没有看过xUnit++,那么我专门制作它是因为我对可用的内容(包括 gtest)不满意。您的大部分列表都受支持,如果不支持,如果它是“必备”功能,我可能愿意添加它。