Agile Project Planning

ExtremePlanner: Agile Project Management for Distributed Software Teams
Click For Your Free Online Trial

Sunday, October 09, 2005

Designing Testable User Interfaces

One of the biggest challenges in software development is creating graphical user interfaces that are easy to test. For small teams especially, having the ability to automate tests that interact with the GUI can save a great deal of manual testing effort.

Conventional wisdom suggests that to test a GUI application, you should test below the interface itself, and design an application that has a very thin UI shell. But how would you test even a simple Scribble application that let you draw on the screen?

One approach would be to design the application to support scripting. In effect you create a protocol for the presentation layer than can be driven by automation. This is the approach that testing tools for Web applications take, since HTTP and HTML offer a well-defined protocol for both taking actions and rendering the results.

So for our Scribble application, we need to be able to draw on the screen, and test to see if what we drew actually appears. The protocol could be as simple as a way to plot a point, and a way to test if a point on the screen is plotted. And maybe a way to save and load the image.

- Plot point x, y
- Test point x, y
- Save as file
- Load file

With these simple primitives, we can now write automated acceptance tests for our Scribble application. We can test existing images to verify that what we know is in the file will be displayed properly in Scribble. We can draw to the edges and see if anything breaks. Most importantly, we can develop a suite of tests that can be run automatically whenever Scribble is updated in the future.

By thinking about how to design our user interfaces to be testable, we also allow them to be useful outside of their original intended purpose. Even our simple Scribble application could be controlled from a statistical package that doesn't have it's own drawing features to do some simple charting.

So make your user interfaces scriptable, and reap the benefits for testing now, and maybe something even more interesting later.


For more on agile tools and techniques: http://www.extremeplanner.com

Get your copy of the new book! Agile Thinking: Leading Successful Software Project and Teams

1 Comments:

  • I have found another method to be useful as well. I can make a fully testable interface with very little change to the way you do things.

    What I do is make an Interface which encompasses everything a human user would do. For instance, suppose I have a form MainForm, and I want to check that when you click the Increment button, the amount goes up by one - I end up with this:

    class MainFormTests
    {
    public void TestIncrement()
    {
    MainFormTester form = StartMainForm();
    int oldValue = Convert.ToInt32(form.DisplayedAmount);
    form.ClickIncrement();
    Assert.AreEqual( oldValue + 1, Convert.ToInt32(form.DisplayedAmount),
    "Check the value has been incremented");
    }
    }

    So I make an interface, MainFormTester which encompasses the things that a user can do - ie "looking at stuff" and "clicking stuff" and "typing stuff"

    public interface MainFormTester
    {
    string DisplayedAmount {get;}
    void ClickIncrement();
    }

    The key point is, and what makes it a completely valid test is that when you increment this interface, you only increment it at a level external to your internal processing - when you read values, you read them from the control's text properties - when you perform actions, you perform them on the controls, not call the internal functions that occur.

    eg:
    string MainFormTester.DisplayedAmount
    { get {return _amount.Text;}}

    void ClickIncrement()
    {
    _incrementButton.PerformClick();
    }

    I tried the scripting approach for a few years, but found that it was very open to issues like timing problems - you end up spending a lot of time just debugging the tests. I came up with this "Interfaced User" method to fix a lot of the problems I was having, and found that it's both incredibly simple to implement, and absolutely rock solid.

    By Blogger Darren Oakey, at 7:48 AM  

Post a Comment

Links to this post:

Create a Link

<< Home