<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Unit Testing Flex &#8211; Alerts</title>
	<atom:link href="http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/feed/" rel="self" type="application/rss+xml" />
	<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 18 Aug 2010 04:20:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Brian</title>
		<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/#comment-28</link>
		<dc:creator><![CDATA[Brian]]></dc:creator>
		<pubDate>Thu, 03 Sep 2009 19:42:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.compactcode.com/?p=253#comment-28</guid>
		<description><![CDATA[@Shanon - I agree with you, when you pass functions around, testing becomes limited to what executes the code, rather than what the code itself does.  If this is the case, why not just utilize a method from the scope chain that can be mocked on an object.  This way you guarantee the same behavior on each call because you&#039;re using a predefined method.]]></description>
		<content:encoded><![CDATA[<p>@Shanon &#8211; I agree with you, when you pass functions around, testing becomes limited to what executes the code, rather than what the code itself does.  If this is the case, why not just utilize a method from the scope chain that can be mocked on an object.  This way you guarantee the same behavior on each call because you&#8217;re using a predefined method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shanon</title>
		<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/#comment-27</link>
		<dc:creator><![CDATA[Shanon]]></dc:creator>
		<pubDate>Tue, 25 Aug 2009 06:09:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.compactcode.com/?p=253#comment-27</guid>
		<description><![CDATA[I apologize for not making myself clear. In my previous posts I am talking about my dislike for this piece of code:

&lt;pre&gt;
  mock.method(”confirm”).calls(
    function () : void {
      wasDeleted = true;
    }
  ).once;
  mock.verify();
&lt;/pre&gt;

My problem is that this does not provide adequate coverage of the production code. It tests a &lt;strong&gt;copy&lt;/strong&gt; of the production code. The reason this is a problem is that I could change my production code to look like this....

&lt;pre&gt;
  public function deleteCustomer(customer:Customer): void {
    confirmer.confirm(
      function(): void {
        throw new Error(&#039;My production code is broken&#039;);
      }
    );
  }
&lt;/pre&gt;

And my test would still pass.]]></description>
		<content:encoded><![CDATA[<p>I apologize for not making myself clear. In my previous posts I am talking about my dislike for this piece of code:</p>
<pre>
  mock.method(”confirm”).calls(
    function () : void {
      wasDeleted = true;
    }
  ).once;
  mock.verify();
</pre>
<p>My problem is that this does not provide adequate coverage of the production code. It tests a <strong>copy</strong> of the production code. The reason this is a problem is that I could change my production code to look like this&#8230;.</p>
<pre>
  public function deleteCustomer(customer:Customer): void {
    confirmer.confirm(
      function(): void {
        throw new Error('My production code is broken');
      }
    );
  }
</pre>
<p>And my test would still pass.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/#comment-26</link>
		<dc:creator><![CDATA[Brian]]></dc:creator>
		<pubDate>Mon, 24 Aug 2009 19:01:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.compactcode.com/?p=253#comment-26</guid>
		<description><![CDATA[@Shannon - In your example, you&#039;re testing CustomerListModelTest.  The mocking framwork is useful to emulate dependencies on the class you&#039;re testing.  If you wanted to test AlertConfirmer, you&#039;d have to write a separate test (e.g. - AlertConfirmerTest).  If you find a mocking framework that supports static method mocking, then you can mock Alert.show() in that AlertConfirmerTest.  From there no need to test Alert.show() it&#039;s a framework method for which you&#039;re not responsible.

You can still practice TDD this way.  Once you saw the need for the AlertConfirmer, you could have written the test for AlertConfirmer and then implemented it.  In fact the mocking framework allows you to mock AlertConfirmer so you can finish the test for CustomerListModelTest before you even tackle implementing CustomerListModel and then you could go on to write AlertConfirmerTest and then AlertConfirmer.

In terms of a unit testing guide, I&#039;d suggest checking out the wiki for the fluint testing framework and flexunit4.  THere are a lot of great examples showing how to perform Theory and DataPoint tests, SequenceSteppers, Async testing, etc.  Best of luck on the endeavor.]]></description>
		<content:encoded><![CDATA[<p>@Shannon &#8211; In your example, you&#8217;re testing CustomerListModelTest.  The mocking framwork is useful to emulate dependencies on the class you&#8217;re testing.  If you wanted to test AlertConfirmer, you&#8217;d have to write a separate test (e.g. &#8211; AlertConfirmerTest).  If you find a mocking framework that supports static method mocking, then you can mock Alert.show() in that AlertConfirmerTest.  From there no need to test Alert.show() it&#8217;s a framework method for which you&#8217;re not responsible.</p>
<p>You can still practice TDD this way.  Once you saw the need for the AlertConfirmer, you could have written the test for AlertConfirmer and then implemented it.  In fact the mocking framework allows you to mock AlertConfirmer so you can finish the test for CustomerListModelTest before you even tackle implementing CustomerListModel and then you could go on to write AlertConfirmerTest and then AlertConfirmer.</p>
<p>In terms of a unit testing guide, I&#8217;d suggest checking out the wiki for the fluint testing framework and flexunit4.  THere are a lot of great examples showing how to perform Theory and DataPoint tests, SequenceSteppers, Async testing, etc.  Best of luck on the endeavor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shanon</title>
		<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/#comment-25</link>
		<dc:creator><![CDATA[Shanon]]></dc:creator>
		<pubDate>Sun, 23 Aug 2009 10:19:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.compactcode.com/?p=253#comment-25</guid>
		<description><![CDATA[I guess the only concern regarding that approach is that if I stub the confirm method/function then I would never actually test the real implementation. I&#039;m really into TDD so I try my hardest to have a failing test in front of me before I write any production code. In any case I accept that the majority of times using a mocking framework is a preferable approach.

I&#039;m currently looking at putting together a small sample application to serve as a guide for those interesting in unit testing flex code. I&#039;m looking at getting stuck into that this week, time permitting. If you have any ideas or thoughts on what should be included or you would like to get involved, send me an email @ shanonmcquay@gmail.com.]]></description>
		<content:encoded><![CDATA[<p>I guess the only concern regarding that approach is that if I stub the confirm method/function then I would never actually test the real implementation. I&#8217;m really into TDD so I try my hardest to have a failing test in front of me before I write any production code. In any case I accept that the majority of times using a mocking framework is a preferable approach.</p>
<p>I&#8217;m currently looking at putting together a small sample application to serve as a guide for those interesting in unit testing flex code. I&#8217;m looking at getting stuck into that this week, time permitting. If you have any ideas or thoughts on what should be included or you would like to get involved, send me an email @ <a href="mailto:shanonmcquay@gmail.com">shanonmcquay@gmail.com</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/#comment-24</link>
		<dc:creator><![CDATA[Brian]]></dc:creator>
		<pubDate>Fri, 21 Aug 2009 19:48:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.compactcode.com/?p=253#comment-24</guid>
		<description><![CDATA[@Shanon - If you use a mocking framework and set an expectation that confirm() should be called, you can verify that the method was called by deleteCustomer using expectations and feel good that your class is interacting with its dependencies correctly.  The anonymous function is just help to stub the confirm method, so don&#039;t feel dirty for using it, all you care about is that confirm is being called correctly.  In mock-as3, this would be written something like:

mock.method(&quot;confirm&quot;).calls(function () : void {
   wasDeleted = true;
}).once;
mock.verify();

The idea of using a mock object framework is not only to stub the return value or error being thrown, but set expectations on how the dependencies should be used using withArgs() and methods to determine the # of calls for a method/properties on a dependency (once/twice/exactly).

Hope you enjoy FlexUnit4.]]></description>
		<content:encoded><![CDATA[<p>@Shanon &#8211; If you use a mocking framework and set an expectation that confirm() should be called, you can verify that the method was called by deleteCustomer using expectations and feel good that your class is interacting with its dependencies correctly.  The anonymous function is just help to stub the confirm method, so don&#8217;t feel dirty for using it, all you care about is that confirm is being called correctly.  In mock-as3, this would be written something like:</p>
<p>mock.method(&#8220;confirm&#8221;).calls(function () : void {<br />
   wasDeleted = true;<br />
}).once;<br />
mock.verify();</p>
<p>The idea of using a mock object framework is not only to stub the return value or error being thrown, but set expectations on how the dependencies should be used using withArgs() and methods to determine the # of calls for a method/properties on a dependency (once/twice/exactly).</p>
<p>Hope you enjoy FlexUnit4.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shanon</title>
		<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/#comment-23</link>
		<dc:creator><![CDATA[Shanon]]></dc:creator>
		<pubDate>Thu, 20 Aug 2009 23:17:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.compactcode.com/?p=253#comment-23</guid>
		<description><![CDATA[Hi Brian,

Glad that you pulled me up on not using a mocking framework. I&#039;m actually using mockito-flex in my day to day work and really liking it! The main problem with auto mocking in the example is the fact that I&#039;m passing an anonymous function to the confirmer:

function(): void {
  wasDeleted = true;
}

As part of my test I need to make sure this function is invoked to verify that it works. I couldn&#039;t find a way to do this with mockito-flex.

Just for you I&#039;ll have a go using FlexUnit 4 for my next flex post :)

Thanks,
Shanon]]></description>
		<content:encoded><![CDATA[<p>Hi Brian,</p>
<p>Glad that you pulled me up on not using a mocking framework. I&#8217;m actually using mockito-flex in my day to day work and really liking it! The main problem with auto mocking in the example is the fact that I&#8217;m passing an anonymous function to the confirmer:</p>
<p>function(): void {<br />
  wasDeleted = true;<br />
}</p>
<p>As part of my test I need to make sure this function is invoked to verify that it works. I couldn&#8217;t find a way to do this with mockito-flex.</p>
<p>Just for you I&#8217;ll have a go using FlexUnit 4 for my next flex post <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks,<br />
Shanon</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://compacted.wordpress.com/2009/08/19/flex-unit-testing-alerts/#comment-22</link>
		<dc:creator><![CDATA[Brian]]></dc:creator>
		<pubDate>Thu, 20 Aug 2009 17:08:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.compactcode.com/?p=253#comment-22</guid>
		<description><![CDATA[Just a note, decoupling the Alert code from the CustomerListModel is a good step, but there are tools out there that can be used to avoid you having to create an interface and 2 implementations classes just to support testing.  mock-as3, asmock, and mockito-flex all support type-safe object mocking.  In this example, you could just create AlertConfirmer alone and then stub out the behavior of the confirm() method for testing.

I personally prefer using mock-as3 since it&#039;s extremely simple to use; the type-safe mocking version hasn&#039;t been officially released as of yet, so you can find a copy of it in this sample project I did for a demo:

http://svn.adogo.us/200908/SampleTestsUsingFU4MockAs3/libs/

Also you should look into using flexunit4 instead of the original flexunit.  The async support is much more robust and there are more tools to do integration testing ala what was in the fluint library.  FlexUnit4 is in beta2 now and it&#039;s quite stable.

Keep pushing the Flex unit testing love, the community needs more great examples.]]></description>
		<content:encoded><![CDATA[<p>Just a note, decoupling the Alert code from the CustomerListModel is a good step, but there are tools out there that can be used to avoid you having to create an interface and 2 implementations classes just to support testing.  mock-as3, asmock, and mockito-flex all support type-safe object mocking.  In this example, you could just create AlertConfirmer alone and then stub out the behavior of the confirm() method for testing.</p>
<p>I personally prefer using mock-as3 since it&#8217;s extremely simple to use; the type-safe mocking version hasn&#8217;t been officially released as of yet, so you can find a copy of it in this sample project I did for a demo:</p>
<p><a href="http://svn.adogo.us/200908/SampleTestsUsingFU4MockAs3/libs/" rel="nofollow">http://svn.adogo.us/200908/SampleTestsUsingFU4MockAs3/libs/</a></p>
<p>Also you should look into using flexunit4 instead of the original flexunit.  The async support is much more robust and there are more tools to do integration testing ala what was in the fluint library.  FlexUnit4 is in beta2 now and it&#8217;s quite stable.</p>
<p>Keep pushing the Flex unit testing love, the community needs more great examples.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

