<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Paul Williams</title>
	<atom:link href="http://www.pmwilliams.co.uk/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.pmwilliams.co.uk/blog</link>
	<description>The blog</description>
	<pubDate>Mon, 03 May 2010 02:30:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The world&#8217;s first accessible Flex application?</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=88</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=88#comments</comments>
		<pubDate>Mon, 03 May 2010 02:30:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<category><![CDATA[accessibility]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk/blog/?p=88</guid>
		<description><![CDATA[For the last six months of 2009 I was working with a team of Flex developers at the Irish Revenue Commissioners on the next version of their innovative PAYE Anytime application. A key objective of this phase of the project was achieving a level of accessibility equivalent to the WCAG &#8216;AA&#8217; standard.
The application incorporates a [...]]]></description>
			<content:encoded><![CDATA[<p>For the last six months of 2009 I was working with a team of Flex developers at the Irish Revenue Commissioners on the next version of their innovative PAYE Anytime application. A key objective of this phase of the project was achieving a level of accessibility equivalent to the WCAG &#8216;AA&#8217; standard.</p>
<p>The application incorporates a number of general features for improved accessibility:</p>
<ul>
<li>Support for &#8220;keyboard-only&#8221; users</li>
<li>An alternative high-contrast style-sheet for vision-impaired users</li>
<li>A zoom feature for vision impaired users</li>
</ul>
<p>We also added features specifically aimed at improving the experience for screen-reader users:</p>
<ul>
<li>Focussable static-text to allow screen-reader users to peruse all content using the tab key</li>
<li>Additional announcements to describe each new view as the user navigates</li>
<li>Additional verbosity to clarify the meaning of buttons and other controls</li>
<li>A skip content feature to allow large areas of content (lists, grids, etc) to be jumped</li>
</ul>
<p>You can <a href="http://www.ros.ie/paye/launchPAYEanytime_en.html" target="_blank">view the application here</a>, but only people working in Ireland and registered for PAYE are able to log-in. Otherwise, you can experience many of the accessibility features on the log-in page or the accompanying product-tour.</p>
<p>There are still fundamental problems that can limit the accessibility of applications developed with Flex. We found fixes for some issues, but we often had to resort to monkey-patching to apply them to the framework.  Other issues have workarounds, but these often require an unnatural change in the browsing behaviour of screen-reader  users. This remains a problem for Flash and Flex: Improving accessibility at the expense of usability is nonsensical.</p>
<p>In addition to problems with the architecture and implementation of accessibility features within Flex there is a general lack of good documentation, articles or tutorials on the subject of accessibility. Many of the tutorials and presentations I&#8217;ve seen offer simplistic advice that is inadequate for the development of anything but the smallest of applications. <a href="https://acrobat.com/" target="_blank">Adobe&#8217;s own Flex applications</a> do not appear to achieve anything close to a WCAG level of accessibility and I&#8217;ve struggled to find any third-party accessible applications online. To help correct this, I hope to share some of our learnings in future blog entries.</p>
<p>However, despite the cheeky title of this post, I doubt this really is the first attempt at an accessible Flex application, so where are all the others?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=88</wfw:commentRss>
		</item>
		<item>
		<title>DataGridColumn now supports nested properties</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=30</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=30#comments</comments>
		<pubDate>Thu, 31 Dec 2009 16:27:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<category><![CDATA[DataGrid]]></category>

		<guid isPermaLink="false">http://blog.pmwilliams.co.uk/?p=30</guid>
		<description><![CDATA[Datagrid fans may be pleased to hear that as of version 3.4 of the SDK, the dataField property of DataGridColumn supports nested properties. This has been an oft-requested feature of the list-based classes, as evidenced by a long-standing issue in the bug-tracking system.
Looking at the framework source, the changes to DataGridColumn source code do not [...]]]></description>
			<content:encoded><![CDATA[<p>Datagrid fans may be pleased to hear that as of version 3.4 of the SDK, the dataField property of DataGridColumn supports nested properties. This has been an oft-requested feature of the list-based classes, as evidenced by a <a href="https://bugs.adobe.com/jira/browse/SDK-9801" target="_blank">long-standing issue</a> in the bug-tracking system.</p>
<p>Looking at the framework source, the changes to DataGridColumn source code do not differ greatly from the community-contributed solutions that already existed. Some optimisations have been introduced such as the parsing of the dataField property once when the property is first set rather than every time the field is evaluated.</p>
<p>Performance concerns appear to be the main reason for omitting this capability from earlier versions. The feature can be expected to be sub-optimal when compared with alternatives such as a labelFunction or custom renderer. However given popular maxims on the evils of premature optimisation, and the availability of more efficient alternatives should the need arise, it seems unnecessary to discard a feature for this reason alone.</p>
<p>My main concern with using dataField for complex expressions is the lack of compile-time checking. A labelFunction may require more code but you&#8217;ll get more help from the compiler if the expression is incorrect. An invalid expression in a dataField property is likely to fail silently and may not be noticed until your testing phase, or perhaps even later. However, if you are generating your columns dynamically or binding to an XML data-provider, then the lack of compile-time checking may be less of an issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=30</wfw:commentRss>
		</item>
		<item>
		<title>Code-hinting problems in Flex Builder</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=22</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=22#comments</comments>
		<pubDate>Tue, 29 Sep 2009 21:07:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Flex Builder]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[completion]]></category>

		<category><![CDATA[flash]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[hinting]]></category>

		<guid isPermaLink="false">http://blog.pmwilliams.co.uk/?p=22</guid>
		<description><![CDATA[Recently there have been a few questions raised in the Flex Forums relating to code-hinting problems with Flex Builder. A quick search on google reveals similar issues reported on other forums and blogs.
The problem is known to occur for users of Flex Builder version 3.0.1 who are compiling with version 3.2 or later of the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently there have been a <a href="http://forums.adobe.com/thread/499353?tstart=0" target="_blank">few</a> <a href="http://forums.adobe.com/thread/499022?tstart=30" target="_blank">questions</a> <a href="http://forums.adobe.com/message/2272549" target="_blank">raised</a> in the Flex Forums relating to code-hinting problems with Flex Builder. A quick search on google reveals similar issues reported on <a href="http://www.actionscript.org/forums/showthread.php3?t=171889" target="_blank">other forums</a> and <a href="http://www.actionscript.org/forums/showthread.php3?t=171889" target="_blank">blogs</a>.</p>
<p>The problem is known to occur for users of Flex Builder version 3.0.1 who are compiling with version 3.2 or later of the Flex SDK. The solution to the problem is to install the Flex Builder 3.0.2 updater available <a href="http://www.adobe.com/support/flex/downloads_updaters.html" target="_blank">here</a>.</p>
<p>The cause of the issue is a recent change to the <a href="http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/flex-config.xml" target="_blank">flex-config.xml</a> file that ships with the SDK. Both Flex Builder and the mxmlc compiler use this configuration file during compilation. The change in question is the addition of the &#8220;targetPlayerMajorVersion&#8221; token into a couple of path-elements. This token is substituted with either &#8220;9&#8243; or &#8220;10&#8243; depending on the Flash player version you are targetting in your build. This in turn causes the compiler to include a particular version of playerglobal.swc during compilation. Although the addition of this token did not prevent earlier versions of Flex Builder from performing builds, it did interfere with code-hinting for many of the core Flash API classes.</p>
<p>If you are unable to install the updater you can also fix the problem by manually removing the targetPlayerMajorVersion token from your flex-config.xml file (located in the frameworks directory) and replacing it with either &#8220;9&#8243; or &#8220;10&#8243; depending on your target player version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=22</wfw:commentRss>
		</item>
		<item>
		<title>Moving on</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=31</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=31#comments</comments>
		<pubDate>Tue, 10 Feb 2009 21:48:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk:/blog/?p=31</guid>
		<description><![CDATA[It&#8217;s been a quite a while since my last set of blog posts and since then I&#8217;ve left Adobe to strike out on my own and found a new home for my musings (which rather conveniently, is right here).
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a quite a while since my <a href="http://blogs.adobe.com/paulw/archives/2008/03/unit_testing_us.html" target="_blank">last set of blog posts</a> and since then I&#8217;ve left Adobe to strike out on my own and found a new home for my musings (which rather conveniently, is right here).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=31</wfw:commentRss>
		</item>
		<item>
		<title>Unit Testing User Interfaces - Autonomous View</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=52</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=52#comments</comments>
		<pubDate>Tue, 30 Sep 2008 09:12:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk/blog/?p=52</guid>
		<description><![CDATA[So far we&#8217;ve looked at possible unit test strategies for presentation models and supervising presenters. Now I want to turn my attention to the Autonomous View pattern. By leaving state and logic in the view, the Autonomous View pattern is arguably one of the simplest presentation patterns to understand and implement. But is it so [...]]]></description>
			<content:encoded><![CDATA[<p>So far we&#8217;ve looked at possible unit test strategies for <a href="http://www.pmwilliams.co.uk/blog/?p=39">presentation models</a> and <a href="http://www.pmwilliams.co.uk/blog/?p=38">supervising presenters</a>. Now I want to turn my attention to the <a href="http://www.pmwilliams.co.uk/blog/?p=47">Autonomous View</a> pattern. By leaving state and logic in the view, the Autonomous View pattern is arguably one of the simplest presentation patterns to understand and implement. But is it so easy to unit test?</p>
<p><span id="more-52"></span></p>
<h2>Challenges </h2>
<p>When attempting to unit test views directly, there are numerous challenges to overcome. </p>
<p><strong>Challenge 1 - Isolating the views:</strong> Strictly speaking, to unit test an autonomous view class we should be creating stub or mock objects for all of the classes it collaborates with. But a typical autonomous view in Flex could collaborate with numerous Flex framework classes. In my example, the AlbumForm collaborates with three TextInputs, one Checkbox, and two Buttons; not to mention container classes like Form and FormItem. Stubbing all of these is no trivial task and not something I&#8217;m going to attempt. So strict unit testing of an autonomous view application is out. </p>
<p>A more sensible approach  would be to treat each distinct autonomous view class as a &quot;unit&quot; for testing purposes, and assume that the Flex controls it contains are part of that unit. So I&#8217;ll create a unit test suite for AlbumForm and AlbumBrowser since these are distinct autonomous views, and when testing AlbumBrowser I&#8217;ll create a stub for AlbumForm.</p>
<p><strong>Challenge 2 -  Creating the view:</strong> When testing presentation models and supervising presenters I instantiated the &quot;class under test&quot; in my test suite&#8217;s setup method. But if I do the same for autonomous views, when I try to access a child of my view instance I get a null pointer exception. This is because my test code is being executed before the view&#8217;s CreationComplete event has fired. So to ensure that the CreationComplete event has been dispatched before my test runs, I have added an asynchronous setup method. This method instantiates the autonomous view, adds it to the display list and then uses the FlexUnit &quot;addAsync&quot; method to trigger the unit test code in response to the view&#8217;s CreationComplete method. </p>
<p><strong>Challenge 3 -  Simulating gestures:</strong> A further problem with unit testing my views is that much of their behaviour is driven directly by user activity. For example the change event of the TextInput class can only occur in response to user input. So I have the following options:</p>
<ul>
<li>Fake the event by calling dispatchEvent on the control and passing it a suitable Event instance that I&#8217;ve created and populated myself..</li>
<li>Drive the control using the Flex automation library</li>
<li>Bypass event dispatch and call the event handler directly from my test.</li>
</ul>
<p>The first of these appears to be the easiest, so that&#8217;s the option I&#8217;m going with.</p>
<p><strong>Challenge 4 - Stubbing the Alert class:</strong> The AlbumBrowser class displays an alert box when the user navigates between albums without saving their changes. I want to test this behaviour, but I don&#8217;t want to see pop-ups appearing during a test run. So I&#8217;ve extracted the pop-up behaviour into a separate class (called YesNoDialogue), and added a stub class for use during test runs.  </p>
<p> <strong>Challenge 5 - Stubbing child views:</strong> I&#8217;ve already said I&#8217;ll create a stub for AlbumForm in order to test AlbumBrowser in isolation of AlbumForm&#8217;s logic. I&#8217;ve done something similar in my previous entries for Presentation Model and Supervising Presenter. In those examples I used a factory method to allow real classes to be substituted with stubs. This works great in ActionScript, but is there a way to swap a real view with a stub when the real view is declared in MXML? Well I gave myself a full 15 minutes to think of one, but nothing came to mind. So in order to stub my AlbumForm, I&#8217;m forced to abandon MXML and create my child view in ActionScript. This is a significant compromise.</p>
<h2>Example Application </h2>
<p>With these challenges overcome or worked around, I could successfully unit test the Autonomous View demo. The unit tested version of the application is <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/autonomousview/UnitTestingAutonomousView.html" target="_blank">available here</a>; right-click to view the source. The test   runner for the unit tests is <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/autonomousview/AllUnitTests.html" target="_blank">available here</a>.</p>
<h2>Thoughts</h2>
<p>This isn&#8217;t so much a tutorial on how to unit test an autonomous view application as an example of why you should avoid trying to. Although many of the challenges can be resolved or worked-around, one in particular presents a real problem. The autonomous view pattern is attractive because of its simplicity; and a large part of that comes from the convenience of MXML for declarative layout. By abandoning MXML in order to unit test,  I am undermining the simplicity of the pattern. </p>
<h2>Further work </h2>
<p>There may be clever ways to stub views in MXML and I admit I didn&#8217;t spend  much time looking at how to achieve this. If you&#8217;ve found an elegant approach for testing this pattern without abandoning MXML I&#8217;d be very interested to hear about it, but I don&#8217;t intend to investigate the topic any further myself. <br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=52</wfw:commentRss>
		</item>
		<item>
		<title>Unit Testing User Interfaces - Supervising Presenter</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=38</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=38#comments</comments>
		<pubDate>Tue, 27 May 2008 08:57:59 +0000</pubDate>
		<dc:creator></dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk/blog/?p=38</guid>
		<description><![CDATA[In my last entry I took a look at unit testing the classes of a simple Presentation Model application. In this entry I&#8217;m going to turn my attention to a functionally-identical Supervising Presenter application. If you cast your mind back to my original investigation of these patterns you&#8217;ll remember that the main difference between Presentation [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://www.pmwilliams.co.uk/blog/?p=39">last entry</a> I took a look at unit testing the classes of a simple Presentation Model application. In this entry I&#8217;m going to turn my attention to a functionally-identical <a href="http://www.pmwilliams.co.uk/blog/?p=46">Supervising Presenter</a> application. If you cast your mind back to my <a href="http://www.pmwilliams.co.uk/blog/?p=48">original investigation</a> of these patterns you&#8217;ll remember that the main difference between <a href="http://www.pmwilliams.co.uk/blog/?p=45">Presentation Model</a> and Supervising Presenter is that the former extracts both state and logic from the view whereas the latter only extracts logic. So in order to receive user events and manipulate view state in response to these events,  supervising presenters maintain a reference to their corresponding view.</p>
<p><span id="more-38"></span></p>
<h2><strong>Challenges</strong></h2>
<p>The first challenge when unit testing supervising presenters is the dependency they have on the view. Since I am trying to follow a strict unit testing strategy, I want my supervising presenters to be tested independently of other classes, including view classes. So I need to find some way to isolate my  presenters from their corresponding views. Besides this unit-testing purism, there are other reasons for isolating my tests from the view:</p>
<ul>
<li>Views are generally relatively slow to instantiate and require a disproportionate amount of resources. Having to create views in order to test classes that depend on them may slow down the running of my test suites.</li>
<li>Animation, deferred instantiaion and modal behaviour could make unit testing challenging. </li>
</ul>
<p>There are probably many ways to decouple presenters from views, but I&#8217;ve decided to follow <a href="http://www.martinfowler.com/eaaDev/SupervisingPresenter.html" target="_blank">Martin Fowler&#8217;s suggestion</a> of creating a &quot;Gateway&quot; between the view and the presenter. Each gateway will have two responsibilities:</p>
<ul>
<li>Act as a <a href="http://en.wikipedia.org/wiki/Facade_pattern" target="_blank">facade</a> for a view. Presenters will access and manipulate the view via the facade.</li>
<li>Observe the view for user events and invoke operations on the presenter.</li>
</ul>
<p>Each view-dependent gateway will implement an interface to allow it to be substituted with a view-independent stub class for use during testing. This <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/supervisingpresenter/srcview/source/diagram.png" target="_blank">UML diagram</a> illustrates the impact of the gateway approach on the original design. </p>
<p>The second challenge is the collaborative relationship between supervising presenters. In order to isolate one supervising presenter from another I&#8217;m going to use the factory method approach described in my previous entry.</p>
<h2>Unit testing AlbumFormPresenter </h2>
<p>The presenter for AlbumForm does not collaborate with any other presenter objects, but I do need to create a gateway class in order to isolate it from the view. I had to make a few changes to the architecture in order to slot in my gateway, and the end result is a gateway object between the view and the presenter called AlbumFormGateway. This gateway class implements the interface IAlbumFormGateway, so that it can be replaced with a test double called StubAlbumFormGateway. The test double does not require the real view, and the AlbumFormPresenter does not differentiate between the real gateway and the stub gateway because they both implement the same interface. So now I can unit test my AlbumFormPresenter class without needing an instance of AlbumForm.</p>
<p><strong>Unit testing AlbumBrowserPresenter</strong> </p>
<p>I also need to create a gateway object for AlbumBrowserPresenter to decouple it from the corresponding view class. This is achieved in precisely the same way as for AlbumFormPresenter. So I&#8217;ve added an AlbumPresenterGateway, IAlbumPresenterGateway and StubAlbumPresenterGateway. </p>
<p>In addition to creating the gateway class, I also need to isolate the functionality of AlbumBrowserPresenter from AlbumFormPresenter. If you recall from my previous entry, a similar relationship existed between the AlbumBrowser and AlbumForm presentation models. So I&#8217;m applying the same factory method approach approach to allow the real AlbumFormPresenter to be replaced by a stub. The result is a new interface IAlbumFormPresenter, and a new stub class StubAlbumFormPresenter. </p>
<p>A further  complexity for AlbumBrowserPresenter is the dependency it has on the PopUpManager. Rather than stub the PopUpManager class I have placed it on the &#8216;view-side&#8217; of the gateway; so the presenter displays the pop-up by calling a method on the gateway. </p>
<p><strong>Unit testing Album</strong> </p>
<p>Unlike the Presentation Model applicaton, the Album VO in the Supervising Presenter example doesn&#8217;t have any methods, so it doesn&#8217;t need to be tested. Or does it?</p>
<p>In order for my application to work the Album VO class does need to do one very important job: It needs to support binding. Should I write unit tests for bindability? Well strictly speaking I should, and perhaps I could use <a href="http://blogs.adobe.com/tomsugden/2008/01/post.html" target="_blank">Tom&#8217;s EventfulTestCase</a> for this. But I think I&#8217;ll look more closely at this another day.</p>
<p><strong>Unit testing AlbumDelegate</strong></p>
<p>As with the Presentation Model example, I&#8217;m not testing this class. </p>
<h2>Example Application </h2>
<p>The unit tested version of the supervising presenter demo application is <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/supervisingpresenter/UnitTestingSupervisingPresenter.html" target="_blank">available here</a>; right-click to view the source. The test   runner for the unit tests is <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/supervisingpresenter/AllUnitTests.html" target="_blank">available here</a>.</p>
<h2>Thoughts</h2>
<p>The supervising presenter&#8217;s view dependency does make unit testing more challenging. The gateway approach appears to be a robust strategy for isolating supervising presenters from views, but it comes at a price. The gateway layer adds extra complexity to the application, and the gateways themselves cannot be unit-tested because they still have dependencies on views. </p>
<h2>Further work </h2>
<p>After going to the trouble of creating gateways I&#8217;m left wondering whether it would be simpler to create test doubles for my actual view classes and dispense with gateways altogether. To do this I would have to extract an interface for each view and then create standalone test doubles that contain identical framework controls. For this to work I would also need to find some way to create fake framework events for my presenters to respond to. I&#8217;m not going to attempt this because I now want to turn my attention to unit testing <a href="http://www.pmwilliams.co.uk/blog/?p=52">autonomous views</a>.<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=38</wfw:commentRss>
		</item>
		<item>
		<title>Unit Testing User Interfaces - Presentation Model</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=39</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=39#comments</comments>
		<pubDate>Tue, 15 Apr 2008 08:54:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk/blog/?p=39</guid>
		<description><![CDATA[As mentioned in the introduction, I&#8217;m going to attempt to unit test my presentation model example application first. Of all the presentation patterns I&#8217;ve looked at, I&#8217;m expecting the presentation model to be the easiest to unit test. 
Challenges
By extracting view state and logic from the view, presentation model classes do not have any dependencies [...]]]></description>
			<content:encoded><![CDATA[<p>As mentioned in the <a href="http://www.pmwilliams.co.uk/blog/?p=40">introduction</a>, I&#8217;m going to attempt to unit test my <a href="http://www.pmwilliams.co.uk/blog/?p=45">presentation model</a> example application first. Of all the presentation patterns I&#8217;ve looked at, I&#8217;m expecting the presentation model to be the easiest to unit test. </p>
<h2>Challenges</h2>
<p>By extracting view state and logic from the view, presentation model classes do not have any dependencies on  view classes. They do sometimes have dependencies on each other, so test doubles may be required to isolate the functionality in one presentation model from functionality in another.</p>
<p><span id="more-39"></span></p>
<h2>Unit testing AlbumForm</h2>
<p>The AlbumForm class is quite straightforward to unit test as it only collaborates with the Album value object. I&#8217;ve decided not to create a test double for the Album VO because of its simplicity. It only has too methods, and I suspect they will be difficult to simulate without duplicating their behaviour.</p>
<p>In the unit test for AlbumForm I have created tests for all of the public methods of the AlbumForm class. Many of the public methods require more than one test in order to exercise every path of execution. </p>
<h2>Unit testing AlbumBrowser</h2>
<p>The AlbumBrowser class is a little harder to unit test because it collaborates with the AlbumForm class. In order to isolate my AlbumBrowser unit tests from the functionality of AlbumForm, I&#8217;ve decided to create a test double for the AlbumForm class. To do this I&#8217;ve made the following changes: </p>
<ul>
<li><strong>Extracted an  interface from AlbumForm</strong> - In order to create a test double for the AlbumForm, I&#8217;ve created an IAlbumForm interface which the AlbumForm now implements. The test double &#8216;StubAlbumForm&#8217; also implementes IAlbumForm allowing it to be used as a substitute for AlbumForm. </li>
<li><strong>Modified AlbumBrowser to work with any IAlbumForm implementation </strong>- Now there&#8217;s more than one way to do this, and I&#8217;ve used a factory method. The AlbumBrowser is modified so that it creates its instance of AlbumForm in a <a href="http://en.wikipedia.org/wiki/Factory_method_pattern" target="_blank">factory method </a>(that&#8217;s just an instance method that is reponsible for constructing the AlbumForm). The factory method is marked protected so that it can be overriden in a subclass. In my AlbumBrowser unit test I&#8217;ve created a private subclass of AlbumBrowser that overrides the factory method to return an instance of StubAlbumForm*. My unit test for AlbumBrowser tests an instance of the private sub-class rather than AlbumBrowser itself. This allows me to test AlbumBrowser functionality in isolation of the AlbumForm class. </li>
<li><strong>Added a property to StubAlbumForm to allow me to control the flow of tests</strong> - The AlbumBrowser takes different actions depending on the result from the &#8216;changesToSave&#8217; method on the AlbumForm class. In order to test these different paths I&#8217;ve added a &#8216;pendingChanges&#8217; property to the StubAlbumForm that allows me to specify the return value of the &#8216;changesToSave&#8217; method.</li>
</ul>
<p>I&#8217;ve also captured these modifications in the form of a UML diagram, so <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/presentationmodel/srcview/source/diagram.png" target="_blank">take a look</a> if none of the above makes any sense.</p>
<p>Together, these changes allow me to test AlbumBrowser in isolation of the AlbumForm class. Doing all of this may be considered overkill for such a small application, but it becomes important for larger applications with deeper hierarchies of presentation model instances and more complex collaborations. </p>
<p><strong>Unit testing Album</strong> </p>
<p>The Album VO doesn&#8217;t collaborate with any other objects, so testing it is very easy. The unit test for the Album class covers the two public methods: clone() and equals(). <br/>
</p>
<p><strong>Unit testing AlbumDelegate</strong></p>
<p>Since this class is a fake delegate, I&#8217;m not going to test it. In real applications it will be necessary to create test doubles for delegates. </p>
<h2>Example Application </h2>
<p>The unit tested version of the presentation model demo application is <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/presentationmodel/UnitTestingPresentationModel.html" target="_blank">available here</a>; right-click to view the source. The test runner for the unit tests is <a href="http://examples.pmwilliams.co.uk/adobeblog/unittestingui/presentationmodel/AllUnitTests.html" target="_blank">available here</a>. </p>
<h2>Thoughts</h2>
<p>The presentation model&#8217;s independence from the view simplifies the unit testing of application-specific user interface logic. The main challenge is isolating the functionality of one presentation model from that of another. I&#8217;ve chosen to use a factory method approach in my application, but other <a href="http://en.wikipedia.org/wiki/Creational_pattern" target="_blank">creational patterns</a> could also be applied, as could some form of <a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">dependency injection</a>.</p>
<p><strong>Further work</strong></p>
<p>The presentation model classes in this application are still not very well encapsulated. Many of the properties the view binds to are public properties; this simplifies binding, but undermines encapsulation. I&#8217;d like to tighten up the encapsulation on these classes, but that&#8217;s a task for another day.</p>
<p><em>*A similar approach in Java would be to use Anonymous Inner Classes inside tests or fixtures to create test-specific sub-classes (here&#8217;s <a href="http://www.ibm.com/developerworks/library/j-mocktest.html" target="_blank">an example</a> from IBM). EcmaScript and consequently ActionScript do not support this language feature, so I&#8217;ve used a private class instead. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=39</wfw:commentRss>
		</item>
		<item>
		<title>Unit Testing User Interfaces - Introduction</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=40</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=40#comments</comments>
		<pubDate>Mon, 24 Mar 2008 07:25:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk/blog/?p=40</guid>
		<description><![CDATA[You may  have caught my last series in which I looked at six different patterns for  organising view logic in a Flex client. In this series I&#8217;m going to take the  demonstration applications for three of those patterns and look at the changes  required to effectively unit test them. The aim [...]]]></description>
			<content:encoded><![CDATA[<p>You may  have caught my <a href="http://www.pmwilliams.co.uk/blog/?p=48">last series</a> in which I looked at six different patterns for  organising view logic in a Flex client. In this series I&#8217;m going to take the  demonstration applications for three of those patterns and look at the changes  required to effectively unit test them. The aim of the exercise is to gain an  insight into how amenable each pattern is to unit testing and hopefully  wrestle with some common unit testing challenges along the way.</p>
<p><span id="more-40"></span></p>
<h2>What is  unit testing?</h2>
<p>This  isn&#8217;t an introduction to unit testing or a tutorial on how to get started with  unit testing. So if you&#8217;re asking this question you may want to have a look at some of the links below. The test tool of choice for this series is <a href="http://code.google.com/p/as3flexunitlib/">Flex Unit</a> as it is the one we use on our consulting projects. There are others out there, so feel free to shop around.</p>
<ul>
<li><a href="http://www.adobe.com/devnet/flex/articles/unit_testing.html" target="_blank">Unit testing and Test Driven Development (TDD) for Flex and ActionScript 3.0</a></li>
<li><a href="http://www.darronschall.com/weblog/archives/000216.cfm" target="_blank">How to use FlexUnit with FlexBuilder 2</a></li>
<li><a href="http://ammonlauritzen.com/blog/2006/11/02/flexunit_basics/" target="_blank">FlexUnit Basics</a></li>
<li><a href="http://blog.iconara.net/2007/02/06/flexunit/" target="_blank">The lost FlexUnit documentation </a></li>
<li><a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=dogooglesearch&amp;searchTagName=flexunit&amp;productId=2&amp;startRow=1&amp;loc=en_US" target="_blank">FlexUnit articles in the Flex Cookbook</a></li>
</ul>
<h2>The plan</h2>
<p>When looking at Presentation Patterns I started with the simplest pattern to  implement, but for this series I&#8217;m going to start with the pattern that I believe will be simplest to unit test. So here&#8217;s the order of business:</p>
<ol>
<li>Presentation Model </li>
<li>Supervising Presenter</li>
<li>Autonomous View</li>
</ol>
<h2>Why test view logic?</h2>
<p>Applying a unit testing strategy to your user interface logic can have more than one advantage:</p>
<ul>
<li><strong>Helps uncover defects early </strong> - This is the obvious one, unit testing should help you detect bugs as you develop your code. It won&#8217;t detect every bug, but it should provide an extra line of defence. </li>
<li><strong>Facilitates refactoring</strong> - Refactoring is something of a buzzword these days and you&#8217;re far more likely to hear people talking about refactoring their code than unit testing it. Refactoring is a structured technique for reducing duplication and redundancy in your code, but without automated unit tests it can also be a great way to add defects. </li>
<li><strong>Helps to communicate intent</strong> - Unit tests can help to describe the intended behaviour of a class. This is of particular importance in team-based software development, or for applications with long maintenance phases. Code commenting and technical documentation are still often favoured over unit testing, but it is debatable whether these are more reliable than a comprehensive suite of unit tests. </li>
<li><strong>Increases the </strong><strong> focus on architecture </strong> - Adopting a unit test strategy forces you to think more about the architecture of your application. Perhaps most significantly, the need to test each class in isolation of its collaborators encourages a developer to code against interfaces rather than concrete classes. You&#8217;re also likely to see fewer global singletons and <a href="http://en.wikipedia.org/wiki/Law_of_Demeter" target="_blank">law of demeter</a> violations in a unit tested application because of the increased emphasis on modularity. </li>
</ul>
<h2>Is this Test Driven Development?</h2>
<p>Test Driven Development (TDD) or test-first development is a development practice in which unit tests are written before the code they test. The advantage of TDD is that the test is seen to fail before the code is written, and the code is then written to make the test pass. I&#8217;m not following a TDD approach in these entries because the applications I&#8217;m testing have already been written.</p>
<p>In my <a href="http://www.pmwilliams.co.uk/blog/?p=39">next entry</a> I&#8217;ll take a look at unit testing my Presentation Model example. <br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=40</wfw:commentRss>
		</item>
		<item>
		<title>Presentation Patterns - Conclusions</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=41</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=41#comments</comments>
		<pubDate>Sun, 03 Feb 2008 17:55:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk/blog/?p=41</guid>
		<description><![CDATA[Towards the end of last year I took a look at six contrasting patterns for  organising presentation logic. Some of these patterns are  well known and popular in the Flex community, others are very rarely discussed.  If you know of any other presentation patterns that you feel are worth looking  at [...]]]></description>
			<content:encoded><![CDATA[<p>Towards the end of last year I took a look at six contrasting patterns for  organising presentation logic. Some of these patterns are  well known and popular in the Flex community, others are very rarely discussed.  If you know of any other presentation patterns that you feel are worth looking  at more closely it would be great to hear about them. </p>
<p><span id="more-41"></span></p>
<h2>Why did I want to do this? </h2>
<h2><em>Establish  a base-line of terminology for future discussions </em></h2>
<p>Over  time, terms like View Helper and Code Behind have become somewhat vague.  Discussions involving them often go awry because participants do not have a  common understanding of these concepts. Having a &quot;pattern language&quot;  is beneficial when investigating architecture, but only if the patterns are  unambiguously defined. So in future discussions I want to be able to link back  to this series if I happen to mention a presentation pattern in passing.</p>
<h2><em>Increase  my own understanding</em></h2>
<p>Some of  the patterns in this discussion have been applied on consulting projects past  and present, while others are architectural curiosities that have piqued my  interest. Building a simple application with each one has helped me to come to  a better understanding of how they contrast. Before starting to develop the  <a href="http://www.pmwilliams.co.uk/blog/?p=46">Supervising Presenter</a> I thought it was very similar to the <a href="http://www.pmwilliams.co.uk/blog/?p=44">View Helper</a>, but it  turned out to be quite different. And despite never being entirely comfortable  with the <a href="http://www.pmwilliams.co.uk/blog/?p=43">Code Behind</a> pattern, it wasn&#8217;t until I saw it side-by-side with  patterns like <a href="http://www.pmwilliams.co.uk/blog/?p=45">Presentation Model</a> and <a href="http://www.pmwilliams.co.uk/blog/?p=42">Passive View</a> that I started to understand  the benefits of a more compositional approach.</p>
<h2><em>Explore  the possibilities with Flex </em></h2>
<p>Knowing  about architectural possibilities is only useful if your target platform is  able to support them. Flex has proved itself more than capable of supporting  all six of these contrasting patterns. Having said that, some of the patterns  do make better use of Flex&#8217;s features than others. Both the Presentation Model  and Supervising Presenter combine extract-class refactorings with elegant use  of MXML bindings and declarative event handlers. On the hand, Passive View and  Code Behind sacrifice these features in order to achieve a greater degree of  ActionScript / MXML separation. </p>
<h2>What  Next?</h2>
<h2><em>Take a  closer look at unit testing </em></h2>
<p>Although  I talked about unit testing throughout these discussions, you may have noticed  that I didn&#8217;t actually do any. The very need to unit test could make or break a  pattern, and can become a driving force for architectural decisions.  Furthermore, the subject of unit testing is broad enough and important enough  to warrant a series of blog entries to itself. So <a href="http://www.pmwilliams.co.uk/blog/?p=40">my next job</a> is to look at how amenable some of these patterns are to unit testing. </p>
<h2><em>Further  exploration of presentation patterns </em></h2>
<p>I kept  the example application for this series very simple because I knew I would have  to implement it six times, this is why many aspects of presentation behaviour  mentioned in the <a href="http://www.pmwilliams.co.uk/blog/?p=48">introduction</a> were not demonstrated. I can see real advantages of moving non-graphical concerns such as navigation, deep-linking and localisation out of the view, so I&#8217;d like to take a closer look at this in the future. </p>
<h2><em>Take a look at integrations patterns</em> </h2>
<p>In RIA  development projects, finding a way to organise your presentation logic in a  way that meets your objectives is a great step forward, but not the only  challenge. The way in which your application interacts with remote services is  also extremely important. So what are the common integration patterns in the  Flex world?<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=41</wfw:commentRss>
		</item>
		<item>
		<title>Presentation Patterns - Passive View</title>
		<link>http://www.pmwilliams.co.uk/blog/?p=42</link>
		<comments>http://www.pmwilliams.co.uk/blog/?p=42#comments</comments>
		<pubDate>Thu, 29 Nov 2007 01:20:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.pmwilliams.co.uk/blog/?p=42</guid>
		<description><![CDATA[Like the Supervising Presenter, the Passive View pattern is a derivative of Model View Presenter (MVP). Martin Fowler split MVP into separate patterns to highlight two common approaches for realising MVP. 
The Passive View pattern also has some similarities with Code Behind since both  achieve a complete separation of ActionScript and MXML.

Key Features

State is [...]]]></description>
			<content:encoded><![CDATA[<p>Like the <a href="http://www.pmwilliams.co.uk/blog/?p=46">Supervising Presenter</a>, the Passive View pattern is a derivative of <a href="http://martinfowler.com/eaaDev/ModelViewPresenter.html" target="_blank">Model View Presenter</a> (MVP). Martin Fowler split MVP into separate patterns to highlight two common approaches for realising MVP. </p>
<p>The Passive View pattern also has some similarities with <a href="http://www.pmwilliams.co.uk/blog/?p=43">Code Behind</a> since both  achieve a complete separation of ActionScript and MXML.</p>
<p><span id="more-42"></span></p>
<h2>Key Features</h2>
<ul>
<li>State is in the view </li>
<li>Logic is in the Presenter </li>
<li>Presenter observes the view </li>
<li>Presenter updates the view </li>
<li>Presenter &lsquo;knows&rsquo; about the view </li>
<li>View does not &lsquo;know&rsquo; about the Presenter </li>
</ul>
<p>The key features of  Passive View are identical to those of Supervising Presenter. The difference between the two patterns is the degree to which logic is extracted from the view. Views in a Supervising Presenter application are allowed to &#8216;observe&#8217; domain or value objects in order to display information, but  views in a Passive View application are managed entirely by their presenter object. </p>
<p>The Supervising Presenter pattern lends itself to User Interface frameworks that have synchronisation features (eg. bindings in Flex), by allowing controls in the view to synchronise directly with underlying domain or value objects. The Passive View pattern prohibits this kind of behaviour in the view, so synchronisation between the view and the data model is managed by the presenter class instead.</p>
<h2>Motivations</h2>
<p>The motivations for the Passive View are similar to those of the Supervising Presenter and <a href="http://www.pmwilliams.co.uk/blog/?p=45">Presentation Model</a>:</p>
<h2><em>Easier to test</em></h2>
<p>By moving all behaviour out of the view, the Passive View pattern is likely to afford the maximum unit test coverage of all the patterns I&#8217;ve looked at. The presenter class has a reference back to the view; so mock objects will be required to test it. </p>
<h2><em>Improved Separation of Concerns</em></h2>
<p>As with the other extract class refactorings, the Passive View pattern can help improve the separation of concerns in an application. By favouring composition over inheritance, Passive View achieves a greater degree of decoupling from the Flex framework than the Code Behind pattern. Presenter classes do not need to extend from Flex containers.</p>
<h2><em>Language Segregation</em></h2>
<p>By moving logic out of the view, the Passive View pattern can achieve similar developer / designer workflow objectives as Code Behind. The resulting view class is free from event handler specifications, binding statements and script blocks.</p>
<h2>Issues</h2>
<p>I think all of the issues identified for Supervising Presenter also apply to the Passive View. Rather than repeating myself, I&#8217;ll just refer you <a href="http://www.pmwilliams.co.uk/blog/?p=46">back to that discussion</a>.</p>
<h2><em>Reduced role for MXML</em></h2>
<p>As I suggested when discussing the Code Behind pattern, I don&#8217;t believe MXML is <em>just</em> for designers. Although it is primarily targetted at describing the look of an application, it also offers features that support developers. Keeping MXML for designers means developers do not have access to MXML bindings and declarative event handler specifications. This isn&#8217;t the end of the world and developers will adapt, but it does mean that some of Flex&#8217;s more powerful features are no longer being used. </p>
<p><em><strong>What about declarative behaviour</strong></em>?</p>
<p>Some presentation behaviour can be achieved  declaratively in MXML;  effects, transitions and validators are all examples. Whether Passive View permits this kind of declarative logic in the view isn&#8217;t clear. It is probably safe to leave graphical behaviour in the view  and drive state changes from the presenter if necessary. Non-graphical behaviour such as validation is probably best moved into the presenter class since it is likely to be more closely related to the underlying data model.</p>
<h2>Example application</h2>
<p> The <a href="http://examples.pmwilliams.co.uk/adobeblog/presentationpatterns/passiveview/PassiveView.html" target="_blank">example application</a> demonstrates the Passive View pattern; right-click to access the source. </p>
<h2>Final thoughts </h2>
<p>The Passive View pattern goes a step further than Supervising Presenter by placing additional constraints on the autonomy of the view. But what interests me most about Passive View is the way in which it achieves similar goals to the Code Behind pattern through the use of composition rather than inheritance. For me this is a reminder that there is usually more than one way to solve a particular problem, and that the popular or mainsteam approach may not always be the best option.<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pmwilliams.co.uk/blog/?feed=rss2&amp;p=42</wfw:commentRss>
		</item>
	</channel>
</rss>

