使用 rspec 测试 C/C++程序

发布于 2024-08-22 07:59:26 字数 52 浏览 9 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

简单气质女生网名 2024-08-29 07:59:26

我知道我正在复活一个古老的问题......但我在搜索 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.

乱世争霸 2024-08-29 07:59:26

Rspec 的描述说:

RSpec 是 Ruby 的原始行为驱动开发框架。

我认为这意味着这个工具是 Ruby 特定的。对于 C++,您可以使用 Boost 测试库 或其他工具。

Description of Rspec says:

RSpec is the original Behaviour Driven Development framework for Ruby.

I think that means this tool is Ruby specific. For c++ you could use Boost Test Library or other tools.

始于初秋 2024-08-29 07:59:26

我不认为 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.

桃扇骨 2024-08-29 07:59:26

我刚刚看到了 ccspec,它看起来很有前途。

https://github.com/zhangsu/ccspec

基本上使用 C++11 构造来制作如下内容就像 rspec 一样。如果您正在寻找像 BDD 工具这样的 rspec,它看起来会符合您的要求。看看该网站上的以下示例:

 class Student {
 public:
  bool hasPapers() const {
    return true;
  }

  string status() const {
    return "alumni";
  }
};

auto student_spec = describe("Student", [] {
  Student subject;

  it("has published papers", [subject] {
    expect(subject.hasPapers()).to(be_truthy);
  });

  it("is alumni", [subject] {
    expect(subject.status()).to(eq("alumni"));
  });
});

这里有人尝试过吗?我不确定它是否具有类似 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:

 class Student {
 public:
  bool hasPapers() const {
    return true;
  }

  string status() const {
    return "alumni";
  }
};

auto student_spec = describe("Student", [] {
  Student subject;

  it("has published papers", [subject] {
    expect(subject.hasPapers()).to(be_truthy);
  });

  it("is alumni", [subject] {
    expect(subject.status()).to(eq("alumni"));
  });
});

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

邮友 2024-08-29 07:59:26

当我开始回到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文