<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Observations on Test-Driving User Interfaces</title>
    <link>http://blog.objectmentor.com/articles/2008/06/22/observations-on-test-driving-user-interfaces</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Observations on Test-Driving User Interfaces</title>
      <description>&lt;p&gt;Test driving user interface development has always been a challenge. Recently, I&amp;#8217;ve worked with two projects where most of the work has been on the user-interface components.&lt;/p&gt;


	&lt;p&gt;The first project is using Adobe Flex to create a rich interface. The team decided to adopt &lt;a href="http://funfx.rubyforge.org/"&gt;FunFX&lt;/a&gt; for acceptance testing. You write your tests in Ruby, typically using &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;Test::Unit&lt;/a&gt; or &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;FunFX places some constraints on your Flex application. You have to define the &lt;span class="caps"&gt;GUI&lt;/span&gt; objects in &lt;span class="caps"&gt;MXML&lt;/span&gt;, the &lt;span class="caps"&gt;XML&lt;/span&gt;-based file format for Flex applications, rather than ActionScript, and you need to add ids to all elements you want to reference.[1]&lt;/p&gt;


	&lt;p&gt;These are reasonable constraints and the first constraint promotes better quality, in fact. The &lt;span class="caps"&gt;MXML&lt;/span&gt; format is more succinct (despite the &lt;span class="caps"&gt;XML&lt;/span&gt; &amp;#8220;noise&amp;#8221;) and declarative than ActionScript code. This is almost always true of UI code in most languages (with notable exceptions&amp;#8230;). Declarative &lt;em&gt;vs.&lt;/em&gt; imperative code tends to improve quality because less code means fewer bugs, less to maintain, and it frees the implementor of the declarative &amp;#8220;language&amp;#8221; to pick the best implementation strategies, optimizations, &lt;em&gt;etc.&lt;/em&gt; This characteristic is typical of Functional Languages and well-designed Domain Specific Languages, as well.&lt;/p&gt;


	&lt;p&gt;I don&amp;#8217;t think you can underestimate the benefit of writing &lt;strong&gt;less&lt;/strong&gt; code. I see too many teams whose problems would diminish considerably if they just got rid of duplication and learned to be &lt;em&gt;concise&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;The second project is a wiki-based application written in Java. To make deployment as simple as possible, the implementors avoided the Servlet &lt;span class="caps"&gt;API&lt;/span&gt; (no need to install Tomcat, &lt;em&gt;etc.&lt;/em&gt;) and rolled their own web server and page rendering components. (I&amp;#8217;m not sure I would have made these decisions myself, but I don&amp;#8217;t think they are bad, either&amp;#8230;)&lt;/p&gt;


	&lt;p&gt;The rendering components are object-oriented and use a number of design patterns, such as page factories with builder objects that reflect the &amp;#8220;widgets&amp;#8221; in the UI, &lt;span class="caps"&gt;HTML&lt;/span&gt; tags, &lt;em&gt;etc.&lt;/em&gt; This approach makes the UI very testable with JUnit and &lt;a href="http://www.fitnesse.org"&gt;FitNesse&lt;/a&gt;. In fact, the development process was a model of test-driven development.&lt;/p&gt;


	&lt;p&gt;However, the final result is flawed!  It is much too difficult to change the &lt;em&gt;look and feel&lt;/em&gt; of the application, which is essential for most UI&amp;#8217;s, especially web UI&amp;#8217;s. The project made the wrong tradeoffs; the design choices met the requirements of &lt;span class="caps"&gt;TDD&lt;/span&gt; very well, but they made maintenance and enhancement expensive and tedious. The application is now several years old and it has become dated, because of the expense of &amp;#8220;refreshing&amp;#8221; the &lt;em&gt;look and feel&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;What should have been done? These days, most dynamic web UI&amp;#8217;s are built with templating engines, of which there are many in the most common programming languages. Pages defined in a templating engine are very declarative, except for the special tags where behavior is inserted. The pages are easy to change. It is mostly obvious where a particular visual element is generated, since most of the &amp;#8220;tags&amp;#8221; in the template look exactly like the tags in the rendered page. &amp;#8220;Declarative&amp;#8221; templates, like good &lt;span class="caps"&gt;DSL&lt;/span&gt;&amp;#8217;s, can be read, understood, and even edited by the &lt;em&gt;stakeholders&lt;/em&gt;, in this case the graphical designers.&lt;/p&gt;


	&lt;p&gt;But how do you test these page templates? When test-driving UI&amp;#8217;s it is important to decide what to test and what &lt;strong&gt;not&lt;/strong&gt; to test. The general rule for &lt;span class="caps"&gt;TDD&lt;/span&gt; is to &lt;em&gt;test anything that can break&lt;/em&gt;.  The corollary, especially relevant for UI&amp;#8217;s, is &lt;em&gt;don&amp;#8217;t test anything when you don&amp;#8217;t care if it changes&lt;/em&gt;.&lt;/p&gt;


	&lt;p&gt;It is usually the &lt;em&gt;dynamic behavior&lt;/em&gt; of the UI that can break and should be tested. Templating engines provide special tags for inserting dynamic behavior in the underlying language (Java, Ruby, &lt;em&gt;etc.&lt;/em&gt;). &lt;em&gt;This&lt;/em&gt; is what you should test. It is usually best to keep the &lt;em&gt;scripts&lt;/em&gt; in these tags as small as possible; the scripts just delegate to code, which can be test-driven in the usual way.&lt;/p&gt;


	&lt;p&gt;I see too many UI tests that compare long strings of &lt;span class="caps"&gt;HTML&lt;/span&gt;. These tests break whenever someone makes a minor &lt;em&gt;look and feel&lt;/em&gt; or other inconsequential change. Part of the art of &lt;span class="caps"&gt;UI TDD&lt;/span&gt; is knowing how to test just what can break and nothing more. In the second project, incidental changes to the UI break tests that should be &lt;em&gt;agnostic&lt;/em&gt; to such changes.&lt;/p&gt;


	&lt;p&gt;To conclude, keep your UI&amp;#8217;s as &lt;em&gt;declarative&lt;/em&gt; as you can. Only test the &amp;#8220;declarations&amp;#8221; (&lt;i&gt;e.g.&lt;/i&gt;, templates) in areas where they might &lt;em&gt;break&lt;/em&gt;, meaning if it changes, it&amp;#8217;s a bug. You&amp;#8217;ll get the full benefits of &lt;span class="caps"&gt;TDD&lt;/span&gt; and the freedom to change the UI easily and frequently, as needed.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; Disclaimer: my information on FunFX is second hand, so I might not have the details exactly correct; see the &lt;a href="http://funfx.rubyforge.org/"&gt;FunFX&lt;/a&gt; documentation for details.&lt;/p&gt;</description>
      <pubDate>Sun, 22 Jun 2008 16:52:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:107f8948-2e28-48d7-a495-85d56801b376</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2008/06/22/observations-on-test-driving-user-interfaces</link>
      <category>Dean's Deprecations</category>
      <category>Testing GUIs</category>
      <category>Design Principles</category>
      <category>TDD</category>
      <category>gui</category>
      <category>declarative</category>
      <category>functional</category>
      <category>design</category>
    </item>
  </channel>
</rss>
