RSS 2.0
# Tuesday, February 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 problem is that needs to run in a single thread process, so when called from inside an NUnit test we need to add the STAThreadAttribute to the Test method.

Of course, this is not a problem when you are writing the Test methods yourself but the way SpecFlow works is that the actual Test method is generated by a tool from your .feature file.

001_features

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

002_features

So you need to add the STAThreadAttribute to this method.

003_features

This works great and I was able to drive the browser and write a few test in no time. The problem is that if you edit every time you edit the .feature file this class will be re-generated and you will have to re-add this attribute. (Note: I forked the repo on GitHub, made a change to the source code and sent a pull request to add this attribute by default, not sure if it will be accepted or not).

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.

005_features

 

You will generate the specification from an item template.

004_features

Conclusion:

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.

For using with WatiN or similar tools to drive the browser I will probably keep using pure cucumber with Ruby at least until the STAThread issue gets solved.

kick it on DotNetKicks.com Tuesday, February 02, 2010 11:45:36 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [1] - Trackback
Programming | Tools
Add The Dynamic Programmer Mippin widget
Navigation
Archive
<February 2010>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213
What I'm reading
Shelfari: Book reviews on your book blog
About the author/Disclaimer
Hernan Garcia I have been a software developer for the last 16 years or so.
I was a journalist before and I still consider myself one.
Besides baseball, programming is my other big passion.

Me on twitter. @TheProgrammer
Certified Scrum Master
© Copyright 2010
Hernan Garcia
Sign In
Statistics
Total Posts: 197
This Year: 15
This Month: 1
This Week: 0
Comments: 70
Themes
Pick a theme:
All Content © 2010, Hernan Garcia