有没有 C++类似于 NUnit 的单元测试库?
我们需要将使用 C# 和 NUnit 开发的单元测试工具迁移到在 Red Hat Linux。
我们希望尽量减少移民方面的努力。
我们正在阅读诸如此类的资源:
http://gamesfromwithin.com/exploring -the-c-unit-testing-framework-jungle
但我们没有看到任何与 NUnit 类似的东西。
We need to migrate a unit test harness developed with C# and NUnit to C++ running on Red Hat Linux.
We want to minimize the efforts in migration.
We are reading resources such as this:
http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle
But we don't see anything similar to NUnit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
您是否考虑过使用CppUnit?
以下是C++ 单元测试框架的概述。
Have You considered using CppUnit?
Here is an overview on unit testing frameworks for C++.
我们使用 Google Mock 和 Google 测试。不过,由于我从未使用过 NUnit,因此无法评论它与 NUnit 的相似之处。
We use Google Mock and Google Test. Having never used NUnit, though, I can't comment on how similar it is to NUnit.
还有 Boost.Test。
And there's Boost.Test.
扩展Mark Bessey的答案< /a>:我真的很喜欢 cxxTest 因为它只是一组 C++ 头文件和文件。 Perl 脚本。只要你有一个C++编译器& Perl,它几乎可以在任何系统上运行。它还具有与 IDE 集成的功能(尽管我没有使用过它们)。
另外,这里有一篇好文章探索 C++ 单元测试框架丛林。这篇文章可能已经过时了(大约 2004 年),但对功能和功能进行了很好的总结。使用以下每个 C++ 单元测试框架的直接示例:
Expanding on Mark Bessey's answer: I really like cxxTest because it's just a set of C++ header files & Perl scripts. As long as you have a C++ compiler & Perl, it will work on nearly any system. It also has features to integrate with your IDE (although I haven't used them).
Also, here's a good article Exploring the C++ Unit Testing Framework Jungle. This post is potentially out of date (circa 2004), but gives a great summary of features & straight-up examples utilizing each of the following C++ unit testing frameworks:
不幸的是,您找不到任何与 NUnit 非常相似的东西。由于 C++ 不具有同样强大的反射能力,因此定义测试的过程需要更加明确,而不是像 NUnit 那样使用属性。
我喜欢 cxxtest 因为它易于设置,并且不需要手动测试注册。
You won't find anything very much like NUnit, unfortunately. Since C++ doesn't have the same strong reflection ability, the process for defining tests needs to be somewhat more explicit, rather than using attributes, as in NUnit.
I like cxxtest because it's easy to set up, and doesn't require manual test registration.
我建议您尝试 UnitTest++:
http://unittest-cpp.sourceforge.net/UnitTest++.html
我不知道它是否与 NUnit 类似,但它功能强大、优雅且易于使用。
I recommend you try UnitTest++:
http://unittest-cpp.sourceforge.net/UnitTest++.html
I don't know if it is similar to NUnit, but it is powerful, elegant, and simple-to-use.
我使用 Boost.Test。我曾经使用 CppUnit,但发现它以 Java/Junit 方式工作,而不是 C++ 方式。例如,使用设置和拆卸方法而不是构造函数和析构函数。此外,测试用例/夹具支持有点费力,因为 C++ 不支持反射。
我发现 Boost.Test 更适合我正在测试的 C++ 代码。它也更强大。一段时间后,我将所有 CppUnit 测试移植到 Boost.Test,这花了大约一天的时间,而且我没有回头。
据我所知,cppunit 背后的人也写了 cxxunit ,它更像是 C++ 风格的。
I use Boost.Test. I used to use CppUnit, but found that it works in a Java/Junit way as opposed to a C++ way. For example using setup and teardown methods instead of constructors and desctructors. Also the Test Case / Fixture support was a little laborious since C++ doesn't support reflection.
I found Boost.Test fitted better with the C++ code I was testing. It is also a lot more powerful. After a while I ported all my CppUnit tests to Boost.Test, this took about a day and I haven't looked back.
As far as I know the person behind cppunit also wrote cxxunit which is more C++esque.
Googletest 的用法与 xUnit 非常相似。 Googlemock 是迄今为止最好的 C++ 模拟框架。这些库是跨平台的,拥有优秀的文档和活跃的用户群。您所需要的只是一个可以处理模板的兼容 C++ 编译器。
CppUnit 的原作者 Michael Feathers 现在推荐 CppUnitLite,这是一个简单的框架。一旦我在 ACCU 2010 上给他带来了 Googlemock 的乐趣,我希望他会接受它:-)
Googletest is very similar in usage to xUnit. Googlemock is by far th best mocking framework for C++. The libraries are cross platform, have excellent documentation and an active user base. All you need is a compliant C++ compiler that can handle templates.
Michael Feathers, the original author of CppUnit, now recommends CppUnitLite, which is a bare bones framework. Once I have regaled him with the joys of Googlemock at ACCU 2010 I hope he'll embrace it :-)
业界有一个相对较新的产品,名为 WinUnit。我还没有时间亲自尝试,但可能值得一看。
There is a relatively new kid on the block called WinUnit. I haven't had time to try it myself but it might be worth a look.
有一个很好的工具,名为 CPPUnit。它最初是由 Michael Feathers 将 JUnit 移植到 C++ 上的。我已经使用过它,它非常棒。但请注意,C++ 中的单元测试比其他语言更难。
There is a good one called CPPUnit. It started its life as a port of JUnit to C++ by Michael Feathers. I have worked with it and it is great. Note though, that unit testing in C++ is harder than in other languages.
有一个叫做 Catch2:
https://github.com/catchorg/Catch2
以下是优点:
There is one called Catch2:
https://github.com/catchorg/Catch2
Here are the advantages:
如果 c++/cli 在红帽上运行,那么你应该能够使用 nunit。最坏的情况是将 c# 代码转换为 c++/cli。也可能比看到 如何使用 NUnit 测试原生 C++ 代码。
相关 is-there-ac-unit-testing -library-that-is-similar-to-nunit cc-testing-framework-like-junit-for-java
if c++/cli runs on red hat, then you should be able to use nunit. worst case is just convert the c# code to c++/cli. also it may be easier than that see How to use NUnit to test native C++ code.
related is-there-a-c-unit-testing-library-that-is-similar-to-nunit c-c-testing-framework-like-junit-for-java