Story Telling with WatiN

We use WatiN for integration and user acceptance testing (UATs).Example

[Test]public void PageForwardButtonRendersNextPage(){    ie.GoTo("http://localhost/offices/lists.rails");    ie.Link("fwid").Click();    Assert.AreEqual(2, int.Parse(ie.Select("pgs").SelectedItem))}

This version is not bad, but I have to think when I read it. This test has at least two problems.

  1. HTML specifics have leaked into the test
  2. Element ids (fwid, pgs) are not clear

This all adds up to a potentially brittle and unclear test. Below is the same test, but with our Domain Specific Language (DSL) applied.

[Test]public void PageForwardButtonRendersNextPage(){    OpenBrowserTo("offices/list.rails");    ClickPageForwardButton();    AssertCurrentPageNumberEquals(2);}

As you can see, the test is very readable (almost like a story). Not only does the DSL help keep our tests clear, but it also isolates us from HTML changes.I would encourage everyone to try this technique on your tests. It will make your tests more clear and reliable. Heck, your customer might even be able to read it ;)As always your comments are welcome.

Advertisements

3 Responses

  1. […] Body from WatiN We have added many WatiN tests over the last few weeks. Performance is becoming more important every day. Several of our tests […]

  2. You may be interested to know that I am working on a way for the WatiN Recorder to create a readable model class in a more automatic way.

  3. I am interested. Let me know when I can take a look.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: