如何将 Cppunit 测试迁移到 GoogleTest 中?
我有一堆用 CPPunit 编写的模块测试,以及一些手工创建的模拟。我正在寻找一种尽可能顺利地将它们迁移到 GoogleTest 的方法。 这样的操作你尝试过吗? 需要付出什么努力?
I have a bunch of module tests written in CPPunit with some mocks created by hand. I am looking for a way to migrate them to GoogleTest as smoothly as possible.
Have you tried such an operation?
What was the effort needed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Google Test
和Cppunit
似乎在调用测试方面共享一些相同的语法,但我怀疑该语法有太多差异。我几乎可以肯定你无法以某种方式自动化它,并且此操作需要重新思考和重新组合你的测试以遵循
Google Test
语义(如果你使用专门的东西来创建你的模拟,然后将它们移植到Google Mock
需要更多的努力,仅仅是因为Google Mock
的方法并不明显,而且实际上很复杂)。我想说你最好重新思考以下问题:“为什么我需要移植我的测试”,“这个操作有什么好处”以及“我真的想研究一个全新的测试框架然后重写吗?”我所有的测试都是出于某种目的”。
Google Test
andCppunit
seem to share somewhat the same syntax for invoking tests but as I suspect have too much differences in that syntax.I'm almost sure you can't somehow automate it and this operation would require rethinking and recompositioning of your tests to follow the
Google Test
semantics (if you use something specialized to create your mocks, then porting them toGoogle Mock
would require even more effort, simply becauseGoogle Mock
's approach is not the obvious one and is actually complicated).I would say that you'd better rethink the following questions: "why do I need to port my tests", "what would be the benefit of this operation" and "do I really want to study a whole new testing framework and then rewrite all of my tests for some purpose".
看来您可以使用另一个框架(cppunit,在您的情况下)的谷歌测试:
https://code.google.com/p/googletest/wiki/AdvancedGuide# Letting_Another_Testing_Framework_Drive
It seems that you can use google test from another framework (cppunit, in your case):
https://code.google.com/p/googletest/wiki/AdvancedGuide#Letting_Another_Testing_Framework_Drive
在某种程度上我同意@Kotti的观点。自动转换对于测试而言并非易事,因此您需要考虑现有测试的数量是否值得付出努力。
我是 Googlemock 框架的超级粉丝,如果您在手动模拟方面投入了大量资金,那么将您的模拟移植到 Googlemock 可能会对您持续的测试成本带来巨大的好处。
如果这是考虑端口的原因,那么请记住 Googlemock 可以与其他测试框架一起使用 - 不仅仅是 Googletest。 (注:我没有使用过这个功能,但是看到过网上的使用报告)
To some extent I agree with @Kotti. Automatic conversion will be non-trivial for the tests, so you'd need to consider whether the number of existing tests justify the effort.
I'm a huge fan of the Googlemock framework, and if you make a significant investment in manual mocking, then porting your mocks to Googlemock could have a huge benefit to your ongoing testing costs.
If this is the reason for considering the port, then remember that Googlemock can work with other test frameworks - not just Googletest. (NOTE: I have not used this feature, but have seen online reports its use)