Re: TDD'ing UI layout.

Phlip <[email protected]> Tue, 15 Nov 2005 06:22:30 -0800
Newsgroups gmane.comp.programming.test-driven-development,gmane.comp.programming.test-first-user-interfaces
Message-ID <[email protected]>
Tim Haughton wrote:

> I've always been a 'thin layer of untestable GUI' kind of guy.
> Recently I started hand rolling GUIs and TDD'ing the whole thing
> (including layout) as part of a learning exercise revolving around how
> far I could push testing on Windows Forms. I'm pretty sure I've found
> the limits. In fact I think I've gone to far.

Windows Forms might hit that limit quite early ;-)

A ruthlessly effective way to test layout for HTML is to generate pure
XHTML. Then capture it, and query into it with XPath. For example:

    node = pathX('//strong["GETTING STARTED" = text()]', '!wiki!README.txt')
    assert_not_nil node

A Wiki is GUI layout entirely driven by internal logic, so every
detail must get tested.

In that sample, '!wiki!README.txt' is Wiki markup notation. !wiki! is
a special command to insert a text file and render it as Wiki markup.

The file README.txt contains the line '''GETTING STARTED''', so the
resulting XHTML should contain <strong>GETTING STARTED</strong>.

The XPath expression '//strong["GETTING STARTED" = text()]' skips over
everything and finds our <strong> tag. So the test must pass if we
find that node.

Similar tests can use the pathX() fixture to query out nodes and then
verify their attributes. This test confirms that an internal <a
href=""> link has its title="" correctly set:

   node = pathX('/span/a[1]/@title', 'WikiConfigExplored!style_editor')
   assert_match /^This page uses WikiConfig/, node.value

All these tests must still pass when XHTML elements around these nodes
upgrade. You could rearrange the <table> tags that compose the pages,
and the XPath queries would still skip over that "glitz" and find the
parts they need to test.

This system allows you to drive development by thinking of new XPath
expressions, first.

> I hear what you're saying with regards to it not often breaking. It's
> just that.....well I can hear Uncle Bob's voice in my head chanting
> "specify, don't verify".

Then channel him saying "don't test the glitz". Use Google Groups to
find the quotes.

--
  Phlip
  http://www.greencheese.org/ZeekLand  <-- NOT a blog!!


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/NhFolB/TM
--------------------------------------------------------------------~-> 

 
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/