First experience with MbUnit and Watin

January 2nd, 2007

During the last two days I’ve completed a project for Castle Stronghold’s client. The project was a complex sign up wizard, built with MonoRail. It involved plenty of javascript validations and ajax calls, and it was a pain no to have automated test cases. So to speed up the process I decided to create a very minimal set of tests and give MbUnit and Watin a try. Usually I’d do it with Watir.

First, MbUnit is nice. I liked the different kinds of test fixtures offered by it, and used the TestSequence a lot. However the project lacks something I find important, which is the API documentation. I usually get to know more of a project by simply navigating the namespaces on Object Browser. Most of attributes, classes and asserts were not documented (except the standard set). I also dislike the wiki-style documentation, but I understand that this is the easy way to maintain a documentation. The problem with this kind of documentation, which btw Castle used to have, is that it does not take the user by hand and teach about the project in small steps.

Another thing I liked about MbUnit was the report generated. It is damn clear about what has failed, be it a SetUp/Teardown, which is something the NUnit lacks. This support alone is enough to make me adopt it right away.

My test sequence was:

public class IndividualRegistrationTestCase : BaseWebTestCase
	[Test, TestSequence(1)]
	public void StartWizard()
		ie = new IE(urlBase + "/registrationindividualwizard/");

		dialogHandler = new SimpleJavaDialogHandler();



	[Test, TestSequence(2)]
	public void FillStep1ForIndividual()
		Assert.AreEqual(urlBase + "/registrationindividualwizard/", ie.Url);

	[Test, TestSequence(3)]
	public void FillAdditionalInfo()

	[Test, TestSequence(4)]
	public void FillBankInfo()

The runner for test sequence also doesn’t detect if a sequence number is repeated, this happened due to a stupid copy & paste…

So MbUnit guys, you’ll have to invest some time on the API docs and producing a nice documentation/web site. For more on this, check the book Producing Open Source Software.

Now Watin is cool. It works just like a Watir and they seem to have tried hard to mimic the niceness of the API exposed by it. I couldn’t test different attributes, like style, though:

string val = ie.Element("labelmsg").GetAttributeValue("style");

This fails with an invalid cast exception. For me, asserting the style is important as a way to check whether the JS validation is working for invalid values. It would be great if the style could be an object, like

Assert.AreEqual("red", ie.Element("labelmsg").Style.Color);

Another thing I didn’t like was


You can guess that the Select will use the text by exclusion. Why not use SelectByText then? The following also doesn’t look good:

Assert.AreEqual("SP", ie.SelectList("step2_State").SelectedItem);

It’s not clear whether SelectedItem will return the text or the value selected. It could expose two variations, SelectedValue and SelectedText which would make it a little bit better.

Anyway, both projects are ready to rock. Increasing the adoption will quickly solve these minor problems as long as they encourage people to send patches/contribute. So hurray, the .net OSS community is finally thriving!

Categories: General, TDD | Top Of Page | 9 Comments » |

9 Responses to “First experience with MbUnit and Watin”

Marcos Says:

Cool, I didn´t know about WatiN, in fact I thought you’re talking about Watir and misspelled the ‘r’. I did some Watir test in the past and it was great, I will try this .NET version right way.

Andy Stopford Says:

Improving the documentation is something I intend to improve this year. The wiki was something that needed to migrate and we do need to improve that. Good to hear your experince with MbUnit went well.

Andrew Stopford's Weblog Says:

Hammet on MbUnit

Castle's main man Hammet has started using MbUnit and Waitin on his projects , this is great to see!

Andy Stopford Says:

The link for MbUnit is not the tigris link you have currently.


WPF Community Bloggers Says:

Hammet on MbUnit

Castle's main man Hammet has started using MbUnit and Waitin on his projects , this is great to see!

Jeroen van Menen Says:


Nice to read WatiN helped you testing your app. I will consider the things you mention about the SelectList methods. An improved implementation is planned for the 1.0 release. I will also create a feature request to support the Style object/property. With the 0.9 and higher release of WatiN you should be able to test the Style settings by using the HTMLElement property on an element, cast this to IHTMLElement (you need to reference the microsoft.mshtml.dll distributed in the distribution zip) and from there on you can acces any property on the “real”/wrapped html element.


Jeremy D. Miller -- The Shade Tree Developer Says:

Automated Web Testing with Watin

I've apparently been living under a rock, because this was new to me. Via Hammet , there is a .Net

Alex Says:

For Web applications developed with AJAX you can also try SWEXplorerAutomation. SWEA ( SWEA fully supports AJAX and doesn’t require “wait|sleep” statements in the test code which greatly improves a test reliability and performance.

Jerrad Anderson Says:

I’ve used the test sequence functionality of mbunit before and it’s a great way to create classic software Test Cases. What I’ve noticed more and more is a divergence of test harnesses. I.e. you have nunit/mbunit tests being written and you have fitnesse/WatiN(R) tests being written to address acceptance testing. Wouldn’t it be awesome if you could write test code that satisfies unit testing and can be reused for functional testing?

I think the key is mbunit’s parameterized test calls.

I’m trying to solve that problem with the new version of systin

Leave a Reply