使用 rspec 测试 C/C++程序
Rspec ruby/rails 是否特定?是否可以将其用作C/C++程序的测试框架?
Is Rspec ruby/rails specific? Is it possible to use it as a test framework for C/C++ program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道我正在复活一个古老的问题......但我在搜索 rspec 和 c++ 时从谷歌获得了这个链接。
Google 自己构建了一个名为 GoogleTest 的(非常易于使用)测试套件,该套件基于 xUnit并被设计为跨平台。
他们还有一个名为 GoogleMock 的模拟框架。
I know I am resurrecting an ANCIENT question... but I get this link from google when searching rspec and c++.
Google itself built a (pretty simple to use) test suite called GoogleTest, that is based on xUnit and designed to be cross-platform.
They also have a mocking framework called GoogleMock.
Rspec 的描述说:
我认为这意味着这个工具是 Ruby 特定的。对于 C++,您可以使用 Boost 测试库 或其他工具。
Description of Rspec says:
I think that means this tool is Ruby specific. For c++ you could use Boost Test Library or other tools.
我不认为 RSpec 适用于 C++,但您应该检查一下这种理解: http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle
根据我的经验:您可以使用 CppUnit,但它有点痛苦。每个测试都有很多开销(开销意味着代码行),因此添加测试变得很烦人。 CppTest 看起来好一点,cxxtest 看起来确实不错,尽管我自己没有使用过后两个。
I don't think that RSpec works for C++, but you should check out this comprehension: http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle
From my experience: You can use CppUnit, but it's somehow painful. There's a lot of overhead per test (overhead means lines of code), so adding tests becomes annoying. CppTest looks a bit better, and cxxtest seems really nice, though I haven't used the last two myself.
我刚刚看到了 ccspec,它看起来很有前途。
https://github.com/zhangsu/ccspec
基本上使用 C++11 构造来制作如下内容就像 rspec 一样。如果您正在寻找像 BDD 工具这样的 rspec,它看起来会符合您的要求。看看该网站上的以下示例:
这里有人尝试过吗?我不确定它是否具有类似 rspec 的模拟功能,但看起来您可以利用 gmock 来进行一些模拟。与 rspec 的功能不完全一样,但可能与 C++11 中的功能最接近
I just saw ccspec, and it looks very promising.
https://github.com/zhangsu/ccspec
Basically uses C++11 constructs to make something that reads just like rspec. It looks like it would fit the bill if your looking for a rspec like BDD tool. Take a look at the following example from the site:
Has anyone here given it a try? I'm not sure if it has rspec like mocking functionality, but it looks like you could leverage gmock to do some mocking. Not quite there feature for feature with rspec, but might be as close as you can get in C++11
当我开始回到 C/C++ 开发并开始寻找类似于 RSpec、Ruby 的 MiniTest 和 Java 的 JUnit 的东西时,我也有同样的想法。
http://sodabrew.com/2012/04/ writing-c-unit-tests-in-ruby.html
此链接显示的是如何使用 FFI gem 将 C/C++ 对象文件加载到 Ruby 中,并像调用本机 Ruby 一样调用它功能。你可能会觉得它很漂亮。
I was thinking the same thing when I started going back into C/C++ development and started looking for something similar to RSpec, or MiniTest for Ruby, and JUnit for Java.
http://sodabrew.com/2012/04/writing-c-unit-tests-in-ruby.html
What this link shows is how to use the FFI gem to load your C/C++ object file into Ruby, and call it almost as though it were a native Ruby function. You might find it nifty.