2011/12/23

Dynamic binding for data-driven tests in MbUnit v3

MbUnit v3.3 has been now released for a while and I realize that I have completely forgotten to write about the new nifty features added by our fellow contributor Aleksandr Jones. Aleks had added a couple of very powerful attributes for writing data-driven tests. He had even written some useful documentation in the Gallio wiki. Those attributes provide a seamless way to bind automatically your external data sources (CSV or XML data files) to the test parameters.

Basically you can declare your test parameters as "dynamic" variables and let MbUnit to bind automagically the parameters behind the scene. Of course it also means that the feature is only available for test projects targeting the .NET 4 framework.

Let's consider the following simple comma-separated example data file:

Name Address City State Url Degree Martial Art
John Smith 123 Test Street New York NY www.yahoo.com Yes Karate
Patricia Doe 72 North Avenue Chicago IL www.google.com Yes Wing Chun
Allen Watts 444 Unit Boulevard Oakland CA www.apache.org No Jiu-Jutsu
view raw Data.csv hosted with ❤ by GitHub
Let's now write a test method which loads the file and gets data from it. We could have used the classic [CsvData] attribute to bind explicitly the parameters. But with the new [FlatFileDataObject] attribute, it's far easier:
[Test, FlatFileDataObject("TestData.csv", FileType.CsvFile)]
public void Test(dynamic RowOfTestData)
{
TestLog.WriteLine(RowOfTestData.ToStringWithNewLines());
TestLog.WriteLine("RowOfTestData.Name ==> " + RowOfTestData.Name);
TestLog.WriteLine("RowOfTestData.Address ==> " + RowOfTestData.Address);
TestLog.WriteLine("RowOfTestData.City ==> " + RowOfTestData.City);
TestLog.WriteLine("RowOfTestData.State ==> " + RowOfTestData.State);
TestLog.WriteLine("RowOfTestData.Url ==> " + RowOfTestData.Url);
TestLog.WriteLine("RowOfTestData.Degree ==> " + RowOfTestData.Degree);
TestLog.WriteLine("RowOfTestData.Martial_Art ==> " + RowOfTestData.Martial_Art);
}
view raw gistfile1.cs hosted with ❤ by GitHub
Look at how the different properties of the test parameter were bound and printed in the test log.
That's just awesome! Good work Aleks!

2011/12/19

Web Testing with MbUnit and WatiN

A serie of articles of mine have been published recently on developerFusion.com. The articles explain how to use efficiently Gallio/MbUnit and WatiN to test your web applications. You can find already many interesting articles about web testing here and there. What I tried to do is to focus on a few less treated problems like testing on the local host, web pages with AJAX requests, controlling the Visual Studio web application server, etc. Good reading!
A big thank you to Dan Maharry and all the editorial team of developerFusion.com for having reviewed my articles.