Using SpecFlow + WatiN or BDD for web applications without leaving the CLR.

Published on Feb 02, 2010

Last week I wrote about using cucumber to test your web applications outside in. In the post I showed a simple example (actually comes with cucumber) to open a browser, go to a site and perform some actions.

I showed the same to my team at work and they mention that could be nice to been able to use c# and Visual Studio to do something similar.

After thinking about it I decided to give another try to a tool I check a few month ago SpecFlow.

SpecFlow is a tool and a set of libraries to write specifications using Gherkin. You can check the screencast here or read this post from Ryan Lanciaux . SpecFlow can use either NUnit or MsTest as the engine.

Now I needed something to drive the browser. WatiN is the .Net port of WatiR and is very easy to use.


The code looks like this (actually I edited it a little bit to make it nicer).


Note: The proper way to do this is to use the following configuration settings in your .config file.

I think that the integration from SpecFlow with VS is great. If you or your team feel very strong on using VS this is a very good tool (there are versions for both VS 2008 and 2010). After writing the features and running the test you will have hints and code to copy and paste from the TestRunner into the specification class.


You will generate the specification from an item template.



I think that this is a great tool, specially if you are using it to develop desktop apps or library code in c#. You can use tools like R# to generate your classes and methods from the step definition class directly.