Richard Lawrence

On making software teams happier and more productive

Archive for the ‘testing’ tag

Debugging Cuke4Nuke Step Definitions

8 comments

At a client today, we were doing some tricky automation with WatiN (against Telerik controls) in Cuke4Nuke. We wanted to dig into what WatiN was finding in the browser. The obvious move was to fire up the debugger. But with Cuke4Nuke, this is trickier than you might think. The Cuke4Nuke gem includes a release build—no debug symbols. Plus, the process isn’t around long enough to attach to if you use the cuke4nuke executable. We probably could have figured it out, but it wasn’t worth the trouble.

Since we weren’t debugging the Cucumber side of things, we didn’t need all the Cucumber and Cuke4Nuke plumbing. We just needed to run the code using WatiN.

NUnit and Resharper to the rescue…Cuke4Nuke cares about Given, When, Then, Before, and After attributes on your methods. But that doesn’t mean those are the only attributes allowed. Read the rest of this entry »

Written by Richard

January 12th, 2010 at 7:52 pm

How to Remove Duplication in Cucumber Tests Using Scenario Outlines

2 comments

Gojko Adzic has a new blog post demonstrating the new table parameter support in Cuke4Nuke. Table parameters are an important part of Cucumber. They’re great for setting up data and asserting that lists are what you expect. But I use them much less often than the other kind of table in Cucumber, scenario outlines. Read on to see how to use them »

Written by Richard

January 4th, 2010 at 10:09 am

The Latest on Cuke4Nuke

one comment

This morning, I released version 0.3.0 of Cuke4Nuke. With this release, Cuke4Nuke supports almost everything you can do with Cucumber in Ruby or Java, making C# a first class language for Cucumber. (The only missing features are small things like tags on Before and After hooks and a richer Table object.) Check out the Cuke4Nuke wiki for instructions to install and get started with Cucumber in .NET. To see it in action, check out my screencast on Cuke4Nuke and WatiN.

Written by Richard

December 30th, 2009 at 10:42 am

WatiN Patterns #3: Don’t Over-specify

3 comments

After a long hiatus, I’m resuming the WatiN Patterns series. Pattern #1 covered why and how your tests should clean up after themselves. Pattern #2 covered how you should name your tests and why they should only assert one thing.

Pattern #3 is about keeping your tests maintainable by specifying just enough in your element selectors.

Read the rest of this entry »

Written by Richard

October 30th, 2009 at 8:20 am

Cuke4Nuke: Cucumber for .NET Teams

5 comments

Update: If you’ve just landed here, you could get the impression from this post that Cuke4Nuke doesn’t exist yet. It does. Check out this screencast showing what you can do with it as of early December 2009.

If you’ve read this blog for a while or talked with me about functional test tools, you’ve heard me talk about Cucumber. It’s my favorite ATDD tool because it’s so good at mapping stories and acceptance criteria to automated functional tests. Product Owners and BAs write acceptance criteria in natural language. Developers and testers unobtrusively automate tests for them. Anyone on the team can run the tests and see the current state of the system.

Here’s a simple example:

Feature: Google search
    In order to find things on the web
    As a user
    I want to search for web pages containing specific text
 
    Scenario: Load search page
        When I go to the search page
        Then I should be on the search page
 
    Scenario: Search
        Given I'm on the search page
        When I search for "richard lawrence"
        Then I should see "www.richardlawrence.info" in the results

This reads almost exactly as I teach Product Owners to specify acceptance criteria. But it’s not just text. It’s a potentially automated test.

A developer or tester can come along and automate this test like so in Ruby:

# assuming @google is an instance of a test DSL that wraps Watir, Selenium, etc. 
 
When /^I search for "(.*)"$/ do |query|
  @google.search_for query
end
 
Then /^I should see "(.*)" in the results$/ do |expected_text|
  assert { @google.results_contain? expected_text }
end
 
# etc...

Each of the Given/When/Then calls is a step definition. When there’s a matching line in a Cucumber test, the step definition gets executed.

Recently, support was added for step definitions in Java via a project called Cuke4Duke:

@When("I search for \"(*)\"")
public void search(String query) throws Exception
{
    google.searchFor(query);
}
 
@Then("I should see \"(*)\" in the results")
public void checkResults(String expectedUrl)
{
    assertThat(google.containsResult(expectedUrl), is(true));
}

Now, a Java team can use Cucumber without ever writing a line of Ruby.

Unfortunately, there’s nothing like this for .NET teams. Until now (or soon, anyway)…

AA-FTT and the Birth of Cuke4Nuke

Last month, I attended the Agile Alliance Functional Test Tool conference (AA-FTT for short). AA-FTT is an open space conference. I came with one goal: to get together with other people who want Cucumber for .NET and start making it happen. I wasn’t sure anyone else would be interested, so I was thrilled with the reaction.

Photo 2 of 4 from #aaftt in Chicago at the pre-conference wor... on Twitpic

Aslak Hellesøy introduced Cucumber for those in the group who hadn’t used it and then talked through the multiple language support he’d recently added to the tool. Then, we discussed ways to build .NET support. The obvious solution was to use IronRuby and Cucumber’s language support to handle C# step definitions. Matt Wynne downloaded the latest IronRuby and installed Cucumber on it. He kicked off a simple Cucumber example, and we waited. And waited. Some two minutes later, we had results from tests that take less than two seconds to run under the standard Ruby interpreter. In a process that values frequent, fast test runs, IronRuby was a non-starter. (If you want to try Cucumber under IronRuby, here are some instructions.)

So we discussed other options and settled on using a simple wire protocol for Cucumber to communicate to .NET out-of-process, similar to Slim in FitNesse. And here’s the best part: we started building it. Matt and I paired right there to start fleshing out the wire protocol (with Cucumber tests, naturally). Later in the week at Agile 2009, Matt and Aslak paired to build the Ruby side of the wire protocol, and Matt and I tackled the first bits of the .NET side. Last week, I got the skeleton of the .NET side working and up on GitHub. You can define simple steps in C#. Cucumber can ask the .NET wire server to tell it about the steps it has and to invoke them and return the pass/fail results.

About a week ago, Aslak announced the project on the Cucumber mailing list and recruited more contributors. Declan Whelan, Scott Ford, Åsmund Eldhuset, Anders Hammervold, Chris Kooken, and Steve Eley have already stepped up with ideas and code.

Getting Involed

How can you get involved? I’m glad you asked.

  1. Join the mailing list.
  2. Fork the GitHub repository and work on one of the features in the backlog.
  3. Post a message to the mailing list to let us know what you’re working on. I’ll tag the ticket in the backlog with your GitHub username so we don’t duplicate effort. Prefix your message subject with [Cuke4Nuke].
  4. Comment on tickets in the backlog.
  5. Try using Cuke4Nuke as we develop it and give us feedback via the mailing list.
  6. Shout encouragements in the comments here and on Twitter to let us know you care, even if you can’t contribute.

Written by Richard

September 19th, 2009 at 5:16 pm

WatiN Patterns #2: One Assertion and a Name to Match

2 comments

One way to keep your WatiN tests maintainable is to keep them small and focused. WatiN Pattern #2, then, is a way to do just that.

Read the rest of this entry »

Written by Richard

February 11th, 2009 at 4:46 pm

WatiN Patterns #1: No Browser Left Behind

no comments yet

In my previous posts on WatiN, I lamented the shortage of online documentation and resolved to do something about it by documenting the patterns I’ve found for good WatiN tests. This is the first in a series in which I’ll take an example of the typical beginner WatiN test I see and refactor it to use the patterns I recommend.

Consider this test:

63
64
65
66
67
68
69
70
71
72
        [TestMethod]
        public void SearchPageTest()
        {
            IE ie = new IE();
            ie.GoTo("http://www.google.com/");
            ie.TextField(Find.ByName("q")).TypeText("Richard Lawrence");
            ie.Button(Find.ByName("btnG")).Click();
            Assert.IsTrue(ie.ContainsText("www.richardlawrence.info"));
            ie.Close();
        }

It has a few problems, but I want to highlight one in this post: This test doesn’t properly clean up after itself. If the code on lines 66-70 throws an exception or if the assertion fails, line 71 will never be executed. When you’re testing on your own machine, this can be annoying—you have to close the IE window manually. But if the test runs unattended (e.g. as part of continuous integration) it can be much more than annoying.

Read the rest of this entry »

Written by Richard

February 4th, 2009 at 4:35 pm

Another Look at WatiN

4 comments

At my current client, we’ve decided to use WatiN, largely for the C# vs. Ruby reason I discussed earlier this week. After spending a week working with WatiN (following a year of rarely using it), I’m impressed. Ruby and the active Watir community still have their advantages. But WatiN has really come into its own with C# 3.0 features like lambdas. I’m pleased with the test code we’re producing in terms of readability, speed, flexibility, and maintainability. I’ve proposed an Agile 2009 tutorial session on the patterns I’m using to get those results, and I’ll post more on that topic here soon. (Which will hopefully help with one of WatiN’s shortcomings—documentation.)

Written by Richard

January 24th, 2009 at 9:29 am

Web Testing for .NET Teams: WatiN or Watir?

3 comments

I’ve noticed a pattern with several of my .NET clients who want to get into automated acceptance testing for web applications. They like the idea of WatiN because it would let them write tests in the same language as their production code. But then they notice that there’s much more documentation and apparently a much more active community around Watir. And that Ruby language looks interesting too. What to do?

I think there are good arguments for both. Here are the major pros and cons from my perspective…

Read the rest of this entry »

Written by Richard

January 19th, 2009 at 8:49 pm

Tagged with , , , , , ,

A Common, but Bad, Idea

one comment

Please don’t do this:

Read the rest of this entry »

Written by Richard

November 13th, 2008 at 9:44 pm