Re: TDD at the GUI end
Phlip <[email protected]>
| Newsgroups | gmane.comp.programming.test-driven-development,gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Message-ID | <[email protected]> |
Donaldson, John (GEO) wrote:
> I'm having some difficulty with TDD close to the GUI.
>
> My tests can instantiate Forms, fill in textboxes and even
> 'performclick'.
> This seems to work quite nicely.
>
> But how to drive behaviour such as MessageBox.Show? Creating a delegate
> of MessageBox.Show seems pretty difficult (it's overloaded) so I suppose
> I could create a wrapper for it, extract the interface, pass a test
> version of this in to the form.
>
> But this means I'm messing with the real code, adding something unusual
> and hard to read just to put in place a test.
>
> Is there a better way?
Write a wrapper class with this MessageBox inside it. (Then hunt down
and smack the developer who made you override a stinkin' message box
just to display it.) Forget testing the wrapper.
Use mock objects to test things with annoying side-effects. Here,
write a mock that spoofs your wrapper class, stores the string
message, and returns this to the test.
And congrats for starting your GUI with tests. Some libraries make
that very easy (treat the GUI Toolkit as just another object). Now
that you have the safety net, writing a detail here and there without
tests is mostly harmless.
> An example: a form with a textbox and a button. On button press,
> evaluate the textbox. If it's blank, just say it's blank; if it's got
> text then see if the text is in the database, report if it is, and if it
> isn't. Commonly we'd use a MessageBox to report, but how to TDD it?
Well, coupling a GUI to the business layer brings bad luck. You need
to TDD that your GUI layer calls the message box wrapper when the biz
layer tells it to, and then you need to TDD that the biz layer
complains when you try to submit blank or redundant data.
In general I suspect you have too few wrappers. Your code should look
less busy than your vendors example code!
--
Phlip
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/testdrivendevelopment/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/