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?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
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.
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.
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.
There seem to be 3 possibilities in this space:
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.
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.
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.
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
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/