PreachingToTheSink

October 09, 2003
I took the time to write this, why not keep it:
9/4/03

EricSink wrote:

> Heh. Good point. :-)
>
> But isn't test-first development a lot harder when
> writing UI code?
>

It can be -- but there are a lot of options for doing this. Some people try to keep their GUI layer very thin and move as much functionality into objects and then only unit test the objects. Or, you just test the GUI.

I've got a Delphi app that I do a lot of GUI testing with -- Delphi lets me do a lot of GUI manipulation for production purposes, why not for testing as well?

begin
f := TMyForm.Create(nil);
try
f.txtEmployeeName.Text := 'Chris Morris';
f.txtEmployeePosition.Text := 'Code Guy Man';
f.btnSave.Click;
finally
f.Free;
end;

f := TMyForm.Create(nil);
try
f.txtSearch.Text := 'Morris';
f.btnLoad.Click;
CheckEquals('Chris Morris', f.txtEmployeeName.Text, 'Name is incorrect');
CheckEquals('Code Guy Man', f.txtEmployeePosition.Text, 'Position is incorrect');
finally
f.Free;
end;
end;

And I've done the same with .NET Windows Forms (in fact, one of the cooler things I started building up was Ruby libraries that would test IE through the COM interfaces and Windows Forms through the COM interoperability interfaces -- that way you could build up a thin web front end in ASP.NET and a thin Windows Forms front end at the same time and use the same automated test scripts to exercise both).

You may counter with, “Well, sure, that's any easy example...” and then come up with a hard one. If it's hard to test automatically, it's usually hard to test manually as well, and hard manual tests will usually never be done regressively because it's prohibitively expensive. But your end users will still do it in production, right? :)

Also, the XP guys like to throw out that changing the production application to accommodate testability should be an okay thing. I recoiled at the thought at first, but now I think it just makes sense. Have an easily tested application has many production benefits.

There can also be some added design benefit - doing this can flush out some interesting GUI designs. Sometimes GUIs I've written don't reveal all the data available because I'm just giving the end user what they wanted. But when I'm GUI testing, there are times I'd like to be able to verify some data through the GUI -- and then I realize, y'know, I'd bet the user might like to see that data, too. Of course, that can get out of hand one way or the other -- nevertheless, what's good for the test is many times good for production and vice-versa.

--

Chris
http://clabs.org/blogki


tags: ComputersAndTechnology AgileDevelopment
comments powered by Disqus