[TFUI] Re: Test first User Interfaces
Phlip <phlipcpp-/[email protected]>
| Newsgroups | gmane.comp.programming.test-first-user-interfaces,gmane.comp.programming.extreme-programming |
|---|---|
| Message-ID | <[email protected]> |
Will Stott wrote:
> I found this at the bottom of Phlip's message. Does
> anyone have any
> comments about testing GUI?
>
>
http://www.xpsd.org/cgi-bin/wiki?TestFirstUserInterfaces
>
> A technique I've used is to make the User Interface
> very, very simple - like
> just setting the controls' (widgets') Text
properties
> - and putting
> everything else in a testable library.
That fix reveals the latent belief that GUIs are
untestable. They are always worth some small effort.
At one end of the spectrum we have forms and fields.
Testing that <Ctrl+C> does indeed copy is useless,
because the field controls are entirely pre-packaged.
At the other end are custom controls, such as a heat
map that permits mouse- and keystrokes to tune the
colors (or the heat). Fortunately for the "make the
GUI thin and don't test it" side, most of business
simply re-uses their GUI toolkit's control sets. Don't
test getters and setters. But learn how.
> I've found that creating a Mock
> Window is an effective way to test such libraries.
At the simple end of that spectrum, windows already
ARE mock windows. All GUI Toolkits that address
generic graphics drivers (meaning all toolkits except
for what we now call embedded systems) use a data
buffer, and only paint on command. If a user
types-ahead before the window displays, and hit Enter
to close it, the window will process the user's inputs
and close without painting.
So if a test never sends the command to paint, the
window never displays. But you can still send messages
to it and get their responses.
After learning to do this, TDD goes from a drag to
seductively convenient. One could build all the
business logic thru simulated GUIs! Don't.
Ideally, one should hit The Test Button as often as
possible, meaning one should defeat any possible
reason not to hit it. A window (or twelve) popping up
would inhibit flow. So for nearly all TFUI-style TDD,
you don't call WM_PAINT, or mainloop(), or whatever,
and you never see the window under test.
If you write a custom control, you either use a canvas
such as TkCanvas that provides in-memory buffering of
all artistry as objects, or you record the calls you
would have sent thru the WM_PAINT system, using a Log
String test.
> However, I would still
> like some way to test interactions between controls,
> e.g. selecting an item
> from listbox A repopulates listbox B and selects its
> first item (which
> repopulates listbox C, ...)
That's easy because listboxes are on the "already
mocked" side - not custom controls.
Don't do it, because such correlations should belong
to a Representation Layer. This translates data
between two formats what the Logic Layer needs, and
what users need. Programming books often say, Make
the GUI code as thin as possible, and put all business
rules into a module without a GUI. That advice
permits testing and developing one aspect of a program
in isolation from another. Our Representation & Logic
Layers can compile, execute, and test without any GUI
Toolkit.
Anything the user can do to a GUI, a programmer can
do, the same way, to a Representation Layer. For
example, if the user can scroll a list box and select
a name, then a programmer could write statements that
fetch a list of names with a method, and could select
the index of one name with another method. The Logic
Layer may or may not keep any names in any list; the
Representation Layer re-arranges data to satisfy
users needs.
However, anything the GUI can do to a user, the
Representation Layer can do to a programmer. If
selecting an item from listbox A repopulates listbox
B, then the Representation Layer should provide a
callback or an Observer Design Pattern to trigger this
repopulation. A test on that Layer would use Self
Shunt to verify the callback occurred, and that the
Layer's representation of the contents of Listbox B
are now refreshed.
=====
Phlip
http://www.xpsd.org/cgi-bin/wiki?TestFirstUserInterfaces
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢
http://photos.yahoo.com/ph/print_splash
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/nhFolB/TM
---------------------------------------------------------------------~->
To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/TestFirstUserInterfaces/
<*> To unsubscribe from this group, send an email to:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/