Question

I love the Ruby RSpec BDD development style. Are there any good tools for doing this with C/C++?

Was it helpful?

Solution

cspec is for C. Presumably it will work with C++. There is a list of tools for various languages on the Behavior Driven Development Wikipedia page.

OTHER TIPS

It seems you can test your C code using Ruby and RSpec using swig to generate wrappers! See Ben Mabey's post here: http://benmabey.com/2007/09/09/bdd-your-c.html

I've tried that example out and it worked for me. I'm not sure if anyone has taken it any further.

The original link (CppSpec) is dead, but it is still accessible at the Internet Archive at CppSpec.

And as @VickyChijwani already mentioned, there's a copy of the project at Github - tpuronen/cppspec

Igloo is one I'm looking forward to try some time

Since an RSpec like framework was requested, I'd like to add the recent igloo. Though originally aiming at Context/Spec syntax, it also supports Describe/It syntax. There isn't much noise in setting the test runner and test fixtures up like in those C-based frameworks. It even feels better to look at than CppSpec. They achieve this through use of decent templating mechanics.

Try CBehave! It is an RSpec-like BDD framework that uses given/when/then macros. Example:

FEATURE(1, "strstr")
    SCENARIO("The strstr finds the first occurrence of the substring in the source string")

       GIVEN("A source string: [Lionel Messi is a great football player]")
           char *str = "Lionel Messi is a great football player";
       GIVEN_END

       WHEN("we use strstr to find the first occurrence of [football]")
           char *p = strstr(str, "football");
       WHEN_END

       THEN("We should get the string: [football player]")
           SHOULD_STR_EQUAL(p, "football player");
       THEN_END
   SCENARIO_END
FEATURE_END
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top