86

Quick one, has anyone come across a library similar to Ruby's cucumber (a human readable DSL for defining use case stories that can be tested against) in the .NET sphere?

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
Owen
  • 6,992
  • 7
  • 44
  • 77

8 Answers8

97

You should also check out SpecFlow, that is an open-source project to do BDD with .NET.

SpecFlow is using the same definition format (Gherkin), like cucumber, but you can write your step definitions in .NET. It basically generates unit-test classes (NUnit, MsTest, xUnit, etc.) from your feature files, so you can use the same unit test execution engine, like you do with the real unit tests. This way it is also easier to integrate the BDD functional tests to the integration build.

In the recent versions SpecFlow has a syntax coloring feature for Visual Studio 2010 and support for Silverlight and Mono/MonoDevelop.

Gaspar Nagy
  • 4,422
  • 30
  • 42
36

Sure. It's called Cucumber. There's an example for how to test .NET code in the Cucumber examples directory and documentation on the Cucumber Wiki for both .NET and Mono.

Community
  • 1
  • 1
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • I attempted this, but kept hitting a bump with running the ICucumber wrapper. The message I got said that the .yml config file was missing. – Owen Jun 11 '09 at 11:27
  • Tried everything described here as well: http://thomaslundstrom.blogspot.com/2009/03/on-getting-started-with-using-cucumber.html – Owen Jun 11 '09 at 11:29
  • 1
    I'm guessing you are referring to this message: "cucumber.yml was not found. Please refer to cucumber's documentation on defining profiles in cucumber.yml. You must define a 'default' profile to use the cucumber command without any arguments. Type 'cucumber --help' for usage. (Cucumber::Cli::YmlLoadError)", right? The obvious question, when a program complains that it couldn't find a file is, is the file actually there or not? Because, if the file is not there, then the reason why it couldn't be found is kind of obvious ... – Jörg W Mittag Jun 11 '09 at 16:01
  • Yes, the file is there. And the link example I posted suggested that the cucumber wrapper was looking in IronRuby's gem folder and not rubys one despite the explicit instruction not to. I did as was suggested and copied the files to my IronRuby's gem folder and nothing. The path in the error looks right, and the file seems to be there. I gave up on this after a few hours of pain. – Owen Jun 13 '09 at 11:07
  • 1
    I still don't quite get what you mean. The link you posted has absolutely nothing whatsoever to do with your problem. And what do you mean by "the file *seems* to be there"? You wrote the file, you saved the file, you should *know* whether it is there or not! – Jörg W Mittag Jun 17 '09 at 21:39
  • 4
    Your examples and wiki links are 404ing – mattumotu Apr 28 '16 at 10:54
21

There seem to be 3 possibilities in this space:

  1. Use Cucumber and IronRuby. Here's a blog on some steps to get started with this. The downside seems to be performance. I've read accounts that say its slower in general, and others that say it's just really slow to spin up. This is far from conclusive though, since IronRuby is still in active development.

  2. Use Cuke4Nuke. I've heard this product recommended a few times. It actually uses regular Ruby and Cucumber but runs your .NET code through a server. Fortunately, all that complication is transparent as you are using it. Cuke4Nuke is no longer under active development.

  3. Use SpecFlow. This is a .NET port of Cucumber. Because of this, it may not have all of Cucumber's features, and it may have extra features. The nice thing is you don't have to have Ruby installed.

At this time it doesn't seem clear which of these is the best option. Personally I'm planning on starting with Cuke4Nuke.

Phil Pill
  • 303
  • 2
  • 14
Kevin Berridge
  • 6,251
  • 6
  • 41
  • 42
  • 3
    For anyone reading this, it seems that Cuke4Nuke is deprecated in favor of SpecFlow http://www.richardlawrence.info/2011/10/21/the-future-of-cucumber-on-net/ – GuiSim May 07 '12 at 18:48
4

StoryTeller is somewhat related even though it is not strictly BDD. It seems to support a somewhat different kind of test but is written in .NET. Read more on Jeremy Millers blog

4

BDD in plain English can be done with Concordion.NET. The specifications of the expected behavior are written in HTML.

Any sentences of any structure can be used for Concordion.NET tests. For example it is not necessary to write a sentence such as "given a bank account with a balance of 10$, when a withdrawal of 20$ is initiated, the transaction fails". Instead any type of sentence could be used such as "a transaction of 20$ fails, if the account contains not enough balance of 10$".

Concordion.NET tests are executed with the help of NUnit, which is integrated in many different environments: https://github.com/concordion/concordion-net

user3632158
  • 277
  • 1
  • 6
3

I wrote up a blog post detailing the process I followed to get Cucumber running with IronRuby: http://hotgazpacho.org/2009/06/cucumber-and-ironruby-it-runs/

Will Green
  • 932
  • 5
  • 10
  • Ill give it a run through and get back to you. – Owen Jun 14 '09 at 21:38
  • I'm also working on porting win32console to IronRuby so that we can get colored console output like we do in MRI: http://github.com/hotgazpacho/ironruby-win32console/ – Will Green Jun 21 '09 at 20:09
2

There is also StoryQ. This is a dev focussed approach to user stories that can report back out clients. http://storyq.codeplex.com

StoryQ is a portable (single dll), embedded BDD framework for .NET 3.5. It runs within your existing test runner and helps produce human-friendly test output (html or text). StoryQ's fluent interface adds strong typing, intellisense and documentation to your BDD grammar.

todd
  • 31
  • 3
1

I have an article showing how to use Cucumber with C# at http://blog.webintellix.com/2009/10/how-to-use-cucumber-with-net-and-c.html The run times have improved dramatically with IronRuby 1.0.

rupakg
  • 510
  • 4
  • 7