Use rspec to test C / C ++ program

Is rspec ruby ​​/ rails specific? Can I use it as a test environment for a C / C ++ program?

+6
c ++ ruby automated-tests rspec
source share
5 answers

Description Rspec says:

RSpec is the source development framework for Driven Driven Development for Ruby .

I think this means that this tool is specific to Ruby. For C ++, you can use the Boost Test Library or other tools.

+1
source share

I don't think RSpec works for C ++, but you should check this understanding: http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle

From my experience: you can use CppUnit, but it is somehow painful. There's a lot of overhead for the test (overhead means lines of code), so adding tests becomes annoying. CppTest looks a little better and cxxtest seems really nice, although I haven't used the last two.

+1
source share

I know that I am raising an ANCIENT question ... but I get this link from google when searching for rspec and C ++.

Google itself has built (quite easy to use) the GoogleTest test suite , which is based on xUnit and is designed for cross-platform.

They also have a mocking structure called GoogleMock .

+1
source share

I just saw ccspec and it looks very promising.

https://github.com/zhangsu/ccspec

It mainly uses C ++ 11 constructs to create something that reads exactly the same as rspec. It seems like this would fit the bill if you were looking for rspec as a 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 tried here? I'm not sure if it has rspec as a mockery of functionality, but it looks like you could use gmock to make a little mockery. Not quite there function for function with rspec, but could be as close as possible to C ++ 11

+1
source share

I was thinking the same thing when I started to return to 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

As this link shows, how to use the FFI gem to load your C / C ++ object file into Ruby and call it almost as if it were a built-in Ruby function. You can find it great.

0
source share

All Articles