22

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

aib
  • 45,516
  • 10
  • 73
  • 79
srboisvert
  • 12,679
  • 15
  • 63
  • 87
  • 3
    Is this question about C or about C++? C/C++ is nothing but pure ambiguity. – amit kumar Sep 13 '11 at 09:04
  • I'm surprised there's no mention of [cucumber-cpp](https://github.com/cucumber/cucumber-cpp), it's an active framework and uses the Gherkin syntax to write the scenarios. It also has a pretty neat set of options to cover many needs. – fduff Aug 14 '18 at 13:36

6 Answers6

14

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.

ejgottl
  • 2,809
  • 19
  • 18
4

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.

TautrimasPajarskas
  • 2,686
  • 1
  • 32
  • 40
user151530
  • 61
  • 2
4

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

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • 4
    The link is broken. Is https://github.com/tpuronen/cppspec the same project? – Vicky Chijwani Mar 24 '13 at 00:08
  • It seems to be the same. Both, the Github repository and [CppSpec](https://web.archive.org/web/20080208105001/http://www.laughingpanda.org/projects/cppspec/) (Internet archive) are signed by Timo Puronen. – Olaf Dietsche Nov 10 '15 at 07:16
3

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

dukeofgaming
  • 3,108
  • 4
  • 28
  • 35
  • it doesn't seem to have any of the characteristics of Cucumber nor Fitnesse, the test is still in the code and it is not readable/editable from tester or business analyst. – Alessandro Teruzzi Nov 10 '16 at 15:50
  • 1
    I don't think igloo-testing.org is a valid website (at least not any longer). – MrMas Feb 15 '19 at 14:54
  • @MrMas is correct. URL appears to go to parked domain / redirect to sketchy places. GitHub repo still exists (June 2019) though: https://github.com/joakimkarlsson/igloo – jacobq Jun 19 '19 at 11:31
2

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
congusbongus
  • 13,359
  • 7
  • 71
  • 99
Tony Bai
  • 151
  • 2
  • 6
2

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.

Sebastian Graf
  • 3,602
  • 3
  • 27
  • 38