<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2009://34.36333-</id>
  <updated>2009-11-16T14:58:33Z</updated>
  <title>Comments for FlashBuilder 4 will support FlexUnit 4 - tutorials and feature overview (http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.36333</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=36333" title="FlashBuilder 4 will support FlexUnit 4 - tutorials and feature overview" />
    <published>2009-05-27T17:00:00Z</published>
    <updated>2009-07-30T20:54:33Z</updated>
    <title>FlashBuilder 4 will support FlexUnit 4 - tutorials and feature overview</title>
    <summary>We don&#8217;t need to be jealous of Java developers anymore. The new version of FlexUnit 4 just got closer in similarity to the JUnit (http://www.junit.org/) project and supports many of the features JUnit has, and more! FlexUnit4 combines features from...</summary>
    <author>
      <name>Elad Elrom</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[We don&#8217;t need to be jealous of Java developers anymore. The new version of FlexUnit 4 just got closer in similarity to the JUnit (<a href="http://www.junit.org/">http://www.junit.org/</a>) project and supports many of the features JUnit has, and more!  FlexUnit4 combines features from the previous FlexUnit 1.0 features and Fluint (<a href="http://code.google.com/p/fluint/">http://code.google.com/p/fluint/</a>).
<br><br>
The FlexUnit team did a splendid job here.  Kudos to the FlexUnit team and particularly to my friends over at Digital Primates:  Michael Labriola&#8217;s and Jeff Tapper&#8217;s.  Check out their blog entries and presentation here:
<br><br>
<a href="http://blogs.digitalprimates.net/codeSlinger/index.cfm/2009/5/3/FlexUnit-4-in-360-seconds">http://blogs.digitalprimates.net/codeSlinger/index.cfm/2009/5/3/FlexUnit-4-in-360-seconds</a><br>
<a href="http://blogs.digitalprimates.net/jefftapper/index.cfm/2009/5/20/FlexUnit-4-feature-overview">http://blogs.digitalprimates.net/jefftapper/index.cfm/2009/5/20/FlexUnit-4-feature-overview</a><br>
<br>
On May 18, 2009, the project moved into the beta phase: <a href="http://opensource.adobe.com/wiki/display/flexunit/FlexUnit+4+feature+overview">http://opensource.adobe.com/wiki/display/flexunit/FlexUnit+4+feature+overview</a><br>
<br>
Additionally, it appears that FlexUnit 4 will be supported, to some extent, by Flex Builder&#133; ooops&#133; I mean Flash Builder 4 (sorry, I am still having a hard time adjusting to the new name!), however, it seems that the plugin class code generated in FB will still support FlexUnit 1 style and not FlexUnit 4.<br><br>

Help support the project by voting to include FlexUnit 4 in Flash Builder 4 here: <a href="http://bugs.adobe.com/jira/browse/FB-18873">http://bugs.adobe.com/jira/browse/FB-18873</a><br>
<br>
I encourage you to download the FlexUnit 4 beta 1 (Turnkey Test Project). The project includes many of the possible tests you can create.<br>
<a href="http://opensource.adobe.com/wiki/display/flexunit/Downloads">http://opensource.adobe.com/wiki/display/flexunit/Downloads</a><br>
<br>
Here are some of the main features:<br>
<br>
1. Easier to create test suite and test cases classes<br>
2. You create test runner easier as well as integrate runners from other frameworks<br>
3. Better usage with continuous integration due to automation integration<br>
4. Better handling of Asynchronous tests<br>
5. Better handling of exceptions<br>
6. Framework is Metadata driven<br>
7. Allows User interface testing<br>
8. Ability to create test sequences<br>
<br>
<strong>Creating Test Suite and Test Case</strong><br>
<br>
We will start off by creating Test Suite and Test Case. To get started let&#8217;s create a new project. Select File -> New -> New Flex Project. Call the project FlexUnit4. Copy the following SWCs into the project libs folder:<br>
FlexUnit1Lib.swc, FlexUnit4.swc, FlexUnit4UIRunner.swc, hamcrest-as3.swc <br>
<br>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="FlexUnit4-01.jpg" src="http://www.insideria.com/FlexUnit4-01.jpg" width="376" height="219" class="mt-image-none" style="" /></span><br>
<br>
<strong>Test Suite</strong><br>
<br>
In FlexUnit 4 your test suite and test case classes don&#8217;t need to inherit from the TestSuite super class anymore. There is also no need to call for a specific Test and Suite classes as we did in FlexUnit 1.  Take a look at a basic Test Suite.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
package flexUnitTests
{
      [Suite]
      [RunWith("<span class="quote">org.flexunit.runners.Suite</span>")]     
      <span class="category1">public</span> <span class="category1">class</span> FlexUnit4Suite
      {
            <span class="category1">public</span> <span class="category1">var</span> flexUnitTester:FlexUnitTester;
       }
}</pre>
</code>

</div></div> 
<br>
Note that we are using the Suite metadata, which indicates that the class is a Suite.  The RunWith tag is used FlexUnit 4.  FlexUnit 4 is a collection of runners that will run to create a complete set of tests.  You can define each runner to implement a specific interface.  For instance, you can select to use the class you reference to run the tests in that class instead of the default runner built into FlexUnit4.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>


[RunWith("<span class="quote">org.flexunit.runners.Suite</span>")]     
[RunWith("<span class="quote">org.flexunit.experimental.theories.Theories</span>")]</pre>
</code>

</div></div> 
<br>
What it means is that the framework is flexible enough to support future runners and allow developers to create their own runners, but still use the same UI. In fact, currently there are runners that exist for FlexUnit 1, FlexUnit 4, Fluint and SLT.<br>
<br>
<strong>Test Case class</strong><br>
<br>
The test case, just as the test suite, doesn&#8217;t have to inherit from the TestCase anymore and got simplified.  The class is based on metadata and although we spoke about RunWith and Suite metadata tags, I would like to introduce you to some more metadata tags available before creating the test case.<br>
<br>
•	[Suite] - indicates that the class is a Suite<br>
•	[Test] - Test metadata replace the test prefixed in front of each method. Support the expected,  async, order, timeout and ui attributes.<br>
•	[RunWith] - Used to select the runner to be used<br>
•	[Ignore] - Instead of commenting out a method you can just place the ignore metadata<br>
•	[Before] - Replaces the setup() method in FlexUnit 1 and allow using multiple methods.  Supports async, timeout, order and ui attributes.<br>
•	[After] - Replaces the teardown() method in FlexUnit 1 and allow using multiple methods. Supports async, timeout, order and ui attributes<br>
•	[BeforeClass] - allow running methods before test class. Supports order attribute.<br>
•	[AfterClass] - allow running methods after test class. Supports order attribute.<br>
<br>
<br>
Take a look at a complete example of a test case class using FlexUnit 4:<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

package flexUnitTests
{
      <span class="category1">import</span> com.elad.framework.utils.Helper;
      <span class="category1">import</span> flash.display.Sprite;
      <span class="category1">import</span> flexunit.framework.Assert;
 
      <span class="category1">public</span> <span class="category1">class</span> FlexUnitTester
      {
            <span class="linecomment">// Reference declaration for class to test</span>
            <span class="category1">private</span> <span class="category1">var</span> classToTestRef : com.elad.framework.utils.Helper;          
  
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//  Before and After</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//--------------------------------------------------------------------------</span>
            
            [Before]
            <span class="category1">public</span> <span class="category1">function</span> runBeforeEveryTest():<span class="category1">void</span> 
            {
                <span class="linecomment">// implement</span>
             }
            
            [After]
            <span class="category1">public</span> <span class="category1">function</span> runAfterEveryTest():<span class="category1">void</span> 
            {
                  <span class="linecomment">// implement</span>
             }                    
            
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//  Tests</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//--------------------------------------------------------------------------</span>
            
            [Test] 
            <span class="category1">public</span> <span class="category1">function</span> checkMethod():<span class="category1">void</span>
            {
                  Assert.assertTrue( <span class="category1">true</span> );
             }
            
            [Test(expected="<span class="quote">RangeError</span>")]
           <span class="category1">public</span> <span class="category1">function</span> rangeCheck():<span class="category1">void</span>
           {
               <span class="category1">var</span> child:Sprite = <span class="category1">new</span> Sprite();
               child.getChildAt(0);
            }
            
            [Test(expected="<span class="quote">flexunit.framework.AssertionFailedError</span>")]
           <span class="category1">public</span> <span class="category1">function</span> testAssertNullNotEqualsNull():<span class="category1">void</span> 
           {
                  Assert.assertEquals( <span class="category1">null</span>, "<span class="quote"></span>" );
            }
           
            [Ignore("<span class="quote">Not Ready to Run</span>")]
            [Test]
            <span class="category1">public</span> <span class="category1">function</span> methodNotReadyToTest():<span class="category1">void</span> 
            {
                Assert.assertFalse( <span class="category1">true</span> );
             }                        
       }
}</pre>
</code>

</div></div> 
<br>
<strong>Assertion methods</strong><br>
<br>
Each test class is based on class we will be testing, therefore it is helpful to create an instance of the class we will be testing so we can have it handy.  Our example here is simple and we aren't really doing a real test of a class.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
        <span class="linecomment">// Reference declaration for class to test</span>
          <span class="category1">private</span> <span class="category1">var</span> classToTestRef : com.elad.framework.utils.Helper;          </pre>
</code>

</div></div> 
<br>
The Before and After metadata tags indicates that these methods will run before and after each test method.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

        [Before]
          <span class="category1">public</span> <span class="category1">function</span> runBeforeEveryTest():<span class="category1">void</span> 
          {
              <span class="linecomment">// implement</span>
           }
          
          [After]
          <span class="category1">public</span> <span class="category1">function</span> runAfterEveryTest():<span class="category1">void</span> 
          {
                <span class="linecomment">// implement</span>
           }                    </pre>
</code>

</div></div> 
<br>
The Test metadata replaces the prefix in front of each method so here we have a method that doesn&#8217;t start with test.  Notice that unlike the previous version of FlexUnit you have to indicate the class to assert since our class doesn&#8217;t inherit from TestCase anymore.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
          [Test] 
          <span class="category1">public</span> <span class="category1">function</span> checkMethod():<span class="category1">void</span>
          {
                Assert.assertTrue( <span class="category1">true</span> );
           }</pre>
</code>

</div></div> 
<br>
In FlexUnit 1 we used to comment out the code to ignore a method that we don&#8217;t want to test any more.  The Ignore metadata tag allows skipping a method.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
          [Ignore("<span class="quote">Not Ready to Run</span>")]
          [Test]
          <span class="category1">public</span> <span class="category1">function</span> methodNotReadyToTest():<span class="category1">void</span> 
          {
              Assert.assertFalse( <span class="category1">true</span> );
           }                        </pre>
</code>

</div></div> 
<br>
<em>Note: In case you want to create a stack order for the tests or the before after methods, you can just add the order attribute, like this:
[Test(order=1)]</em><br>
<br>
<strong>Exception handling</strong><br>
<br>
The test metadata allows defining an exception attribute and makes it possible to test exceptions.  The way it works is that the test method with the expected attributes points to the error message you expect and the test will pass when the exception is raised.<br>
<br>
Let&#8217;s take a look at the example below.  The rangeTest method creates a new Sprite object and tries to get the children at index 0 which exists so we will not get an error message and the test will fail.  To get a success method, change the child.getChildAt(1);  Since child at index 1 doesn&#8217;t exist, the exception will be raised and the test will pass:<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
          [Test(expected="<span class="quote">RangeError</span>")]
         <span class="category1">public</span> <span class="category1">function</span> rangeCheck():<span class="category1">void</span>
         {
             <span class="category1">var</span> child:Sprite = <span class="category1">new</span> Sprite();
             child.getChildAt(0);
          }</pre>
</code>

</div></div> 
<br>
Another example is expecting an assertion error.  Take a look at the testAssertNullNotEqualsNull method.   The method is expecting AssertionFailedError fail error.  The assertEquals method will succeed since null equals null so the test will fail.  Change the statement to the following:<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
Assert.assertEquals( <span class="category1">null</span>, &amp;#8220;&amp;#8221; );</pre>
</code>

</div></div> 
<br>
And you will get the test to succeed.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
         [Test(expected="<span class="quote">flexunit.framework.AssertionFailedError</span>")]
         <span class="category1">public</span> <span class="category1">function</span> testAssertNullNotEqualsNull():<span class="category1">void</span> 
         {
          	Assert.assertEquals( <span class="category1">null</span>, <span class="category1">null</span> );
          }</pre>
</code>

</div></div> 
<br>
<strong>Test runners</strong><br>
<br>
The test runner is similar to FlexUnit1 test runner.<br>
<div class="acode" style="overflow: auto; padding: 10px;" >
<div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;FxApplication xmlns="<span class="quote">http://ns.adobe.com/mxml/2009</span>"
	xmlns:flexUnitUIRunner="<span class="quote">http://www.adobe.com/2009/flexUnitUIRunner</span>"  
	minWidth="<span class="quote">1024</span>" minHeight="<span class="quote">768</span>"
	creationComplete="<span class="quote">creationCompleteHandler(event)</span>"&gt;
	
	&lt;Script&gt;
		&lt;![CDATA[
			<span class="category1">import</span> flexUnitTests.FlexUnit4TheorySuite;
			<span class="category1">import</span> flexUnitTests.FlexUnit4HamcrestSuite;
			<span class="category1">import</span> mx.events.FlexEvent;
			<span class="category1">import</span> flexUnitTests.FlexUnit4Suite;
		
			<span class="category1">import</span> org.flexunit.listeners.UIListener;
			<span class="category1">import</span> org.flexunit.runner.FlexUnitCore;
			
			<span class="linecomment">// holds an instance of the &lt;code&gt;FlexUnitCore&lt;/code&gt; class</span>
			<span class="category1">private</span> <span class="category1">var</span> flexUnitCore:FlexUnitCore;

			protected <span class="category1">function</span> creationCompleteHandler(event:FlexEvent):<span class="category1">void</span>
			{
 				flexUnitCore = <span class="category1">new</span> FlexUnitCore();
 
 				<span class="linecomment">//Listener for the UI, optional</span>
 				flexUnitCore.<span class="category2">addListener</span>( <span class="category1">new</span> UIListener( testRunner ));
 				
 				<span class="linecomment">//This run statements executes the unit tests for the FlexUnit4 framework </span>
 				flexUnitCore.run( FlexUnit4Suite );
 			}

		]]&gt;
	&lt;/Script&gt;
	
	&lt;flexUnitUIRunner:TestRunnerBase id="<span class="quote">testRunner</span>" <span class="category2">width</span>="<span class="quote">100%</span>" <span class="category2">height</span>="<span class="quote">100%</span>" /&gt;
	
&lt;/FxApplication&gt;</pre>
</code>

</div></div> 
<br>
We create an instance of the FlexUnitCore. FlexUnitCore extends EventDispatcher and acts as the facade for running the tests. It mimics the JUnitCore in methods and functionality.  See: <a href="http://junit.sourceforge.net/javadoc_40/org/junit/runner/JUnitCore.html">http://junit.sourceforge.net/javadoc_40/org/junit/runner/JUnitCore.html</a>.
<br><br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
     	<span class="category1">private</span> <span class="category1">var</span> flexUnitCore:FlexUnitCore;</pre>
</code>

</div></div> 
<br>
Once the creationCompleteHandler handler is called we can add the UIListener listener <br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

     	protected <span class="category1">function</span> creationCompleteHandler(event:FlexEvent):<span class="category1">void</span>
     	{
                     flexUnitCore = <span class="category1">new</span> FlexUnitCore();</pre>
</code>

</div></div> 
<br>
We have the option to set listener to the UI.  What&#8217;s happening is that the FlexUnitCore class has async listener watcher, which waits until all listeners are completed before it begins the runner execution.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
                   <span class="linecomment">//Listener for the UI, optional</span>
                  flexUnitCore.<span class="category2">addListener</span>( <span class="category1">new</span> UIListener( testRunner ));</pre>
</code>

</div></div> 
<br>
The next line calls the run method to start executing the tests.  The run method accepts ...args so you will be able to list all the suites you want the runner to run<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
                  <span class="linecomment">//This run statements executes the unit tests for the FlexUnit4 framework </span>
                 flexUnitCore.run( FlexUnit4Suite );
     	}</pre>
</code>

</div></div> 
<br>
We also need an instance of the TestRunnerBase component.<br>
<br>
<flexUnitUIRunner:TestRunnerBase id="testRunner" width="100%" height="100%" />

<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="FlexUnit4-02.jpg" src="http://www.insideria.com/FlexUnit4-02.jpg" width="786" height="434" class="mt-image-none" style="" /></span>
<br>
<strong>Hamcrest assertion method</strong><br>
<br>
In addition to the new standard assertions such as Assert.assertEquals or Assert.assertFalse, FlexUnit 4 supports new methods thanks to Hamcrest (<a href="http://github.com/drewbourne/hamcrest-as3/tree/master">http://github.com/drewbourne/hamcrest-as3/tree/master</a>). Hamcrest is a library that is based on the idea of matchers.  Each matcher can be set to match conditions for your assertions.<br>
<br>
Create a new test case and call it FlexUnitCheckRangeTester.  <br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
package flexUnitTests
{
       <span class="category1">import</span> org.hamcrest.AbstractMatcherTestCase;
       <span class="category1">import</span> org.hamcrest.number.between;
 
      <span class="category1">public</span> <span class="category1">class</span> FlexUnitCheckRangeTester <span class="category1">extends</span> AbstractMatcherTestCase
      {
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//  Before and After</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//--------------------------------------------------------------------------</span>
            
            <span class="category1">private</span> <span class="category1">var</span> numbers:<span class="category2">Array</span>; 
            
            [Before]
            <span class="category1">public</span> <span class="category1">function</span> runBeforeEveryTest():<span class="category1">void</span> 
            {
                numbers = <span class="category1">new</span> <span class="category2">Array</span>( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ); 
             }
            
            [After]
            <span class="category1">public</span> <span class="category1">function</span> runAfterEveryTest():<span class="category1">void</span> 
            {
                  numbers = <span class="category1">null</span>;
             }                    
            
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//  Tests</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//--------------------------------------------------------------------------</span>
          
          [Test]
          <span class="category1">public</span> <span class="category1">function</span> betweenRangeExclusive():<span class="category1">void</span> 
          {
               assertMatches("<span class="quote">assert inside range</span>", between(numbers[0], numbers[10], <span class="category1">true</span>), 5);
               assertDoesNotMatch("<span class="quote">assert outside range</span>", between(numbers[0], numbers[10], <span class="category1">true</span>), 11);
           }        
            
          [Test]
          <span class="category1">public</span> <span class="category1">function</span> betweenRangeInclusive():<span class="category1">void</span> 
          {
               assertMatches("<span class="quote">assert inside range</span>", between(numbers[0], numbers[10]), 5);
               assertDoesNotMatch("<span class="quote">assert outside range</span>", between(numbers[0], numbers[10]), 11);
           }
  
          [Test]
          <span class="category1">public</span> <span class="category1">function</span> betweenReadableDescription():<span class="category1">void</span> 
          {
               assertDescription("<span class="quote">a Number between &lt;0&gt; and &lt;10&gt;</span>", between(numbers[0], numbers[10]));
               assertDescription("<span class="quote">a Number between &lt;0&gt; and &lt;10&gt; exclusive</span>", between(numbers[0], numbers[10], <span class="category1">true</span>));
           }                       
       }
}</pre>
</code>

</div></div> 
<br>
FlexUnit4HamcrestSuite class includes the FlexUnitCheckRangeTester class.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
package flexUnitTests
{
      [Suite]
      [RunWith("<span class="quote">org.flexunit.runners.Suite</span>")]     
      <span class="category1">public</span> <span class="category1">class</span> FlexUnit4HamcrestSuite
      {
            <span class="category1">public</span> <span class="category1">var</span> flexUnitCheckRangeTester:FlexUnitCheckRangeTester;
       }
}</pre>
</code>

</div></div> 
<br>
Lastly, don&#8217;t forget to include the new test suite in FlexUnit4.mxml:<br>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>

flexUnitCore.run( FlexUnit4Suite, FlexUnit4HamcrestSuite );</pre>
</code>

</div></div> 

<br><strong><br>
Asynchronous Tests</strong><br>
<br>
In case you worked with FlexUnit 1 in the past, you know that it isn&#8217;t always easy to create asynchronous tests and test event driven code.  I often found myself modifying existing classes just to accommodate FlexUnit or creating tests in &#8220;hackish&#8221; way.  One of Fluint's biggest advantages is the ability to accommodate multiple asynchronous events. FlexUnit 4 incorporated Fluint functionality and it supports enhanced asynchronous and includes asynchronous setup and teardown.  This feature is possible by every test including the overhead of the asynchronous script.<br>
<br>
Create a new Test Case and call it TestAsynchronous<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
package flexUnitTests
{
      <span class="category1">import</span> flash.events.Event;
      <span class="category1">import</span> flash.events.EventDispatcher;
      
      <span class="category1">import</span> flexunit.framework.Assert;
      
      <span class="category1">import</span> mx.rpc.events.FaultEvent;
      <span class="category1">import</span> mx.rpc.events.ResultEvent;
      <span class="category1">import</span> mx.rpc.http.HTTPService;
      
      <span class="category1">import</span> org.flexunit.async.Async;
 
     <span class="category1">public</span> <span class="category1">class</span> AsynchronousTester
     {
            <span class="category1">private</span> <span class="category1">var</span> service:HTTPService;
            
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//  Before and After</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//--------------------------------------------------------------------------</span>
            
           [Before]
           <span class="category1">public</span> <span class="category1">function</span> runBeforeEveryTest():<span class="category1">void</span> 
           {
                service = <span class="category1">new</span> HTTPService();
                service.resultFormat = "<span class="quote">e4x</span>";
            }
            
           [After]
           <span class="category1">public</span> <span class="category1">function</span> runAfterEveryTest():<span class="category1">void</span> 
           {
                  service = <span class="category1">null</span>;
            }       
            
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//  Tests</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           
             [Test(async,timeout="<span class="quote">500</span>")]
             <span class="category1">public</span> <span class="category1">function</span> testServiceRequest():<span class="category1">void</span> 
             {
                  service.<span class="category2">url</span> = "<span class="quote">../assets/file.xml</span>";
                  service.addEventListener(ResultEvent.RESULT, Async.asyncHandler( <span class="category1">this</span>, onResult, 500 ), <span class="category1">false</span>, 0, <span class="category1">true</span> );
                  service.<span class="category2">send</span>();
              }
            
             [Test(async,timeout="<span class="quote">500</span>")]
             <span class="category1">public</span> <span class="category1">function</span> testeFailedServicRequest():<span class="category1">void</span> 
             {
                  service.<span class="category2">url</span> = "<span class="quote">file-that-dont-exists</span>";
                  service.addEventListener( FaultEvent.FAULT, Async.asyncHandler( <span class="category1">this</span>, onFault, 500 ), <span class="category1">false</span>, 0, <span class="category1">true</span> );
                  service.<span class="category2">send</span>();
              }         
            
             [Test(async,timeout="<span class="quote">500</span>")]
             <span class="category1">public</span> <span class="category1">function</span> testEvent():<span class="category1">void</span> 
             {
                  <span class="category1">var</span> EVENT_TYPE:<span class="category2">String</span> = "<span class="quote">eventType</span>";
                  <span class="category1">var</span> eventDispatcher:EventDispatcher = <span class="category1">new</span> EventDispatcher();
                  
                  eventDispatcher.addEventListener(EVENT_TYPE, Async.asyncHandler( <span class="category1">this</span>,  handleAsyncEvnet, 500 ), <span class="category1">false</span>, 0, <span class="category1">true</span> );
                  eventDispatcher.dispatchEvent( <span class="category1">new</span> Event(EVENT_TYPE) ); 
              }
            
             [Test(async,timeout="<span class="quote">500</span>")]
             <span class="category1">public</span> <span class="category1">function</span> testMultiAsync():<span class="category1">void</span> 
             {
                  testEvent();
                  testServiceRequest();
              }             
           
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//  Asynchronous handlers</span>
           <span class="linecomment">//</span>
           <span class="linecomment">//--------------------------------------------------------------------------</span>
           
           <span class="category1">private</span> <span class="category1">function</span> onResult(event:ResultEvent, passThroughData:<span class="category2">Object</span>):<span class="category1">void</span>
           {
                 Assert.assertTrue( event.<span class="category2">hasOwnProperty</span>("<span class="quote">result</span>") );
            }
           
           <span class="category1">private</span> <span class="category1">function</span> handleAsyncEvnet(event:Event, passThroughData:<span class="category2">Object</span>):<span class="category1">void</span>
           {
                 Assert.assertEquals( event.<span class="category2">type</span>, "<span class="quote">eventType</span>" );
            }         
           
           <span class="category1">private</span> <span class="category1">function</span> onFault(event:FaultEvent, passThroughData:<span class="category2">Object</span>):<span class="category1">void</span>
           {
                 Assert.assertTrue( event.fault.<span class="category2">hasOwnProperty</span>("<span class="quote">faultCode</span>") );
            }         
       }
}</pre>
</code>

</div></div> 
<br>
Adjust the test FlexUnit4Suite.as<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
package flexUnitTests
{
      [Suite]
      [RunWith("<span class="quote">org.flexunit.runners.Suite</span>")]     
      <span class="category1">public</span> <span class="category1">class</span> FlexUnit4Suite
      {
            <span class="category1">public</span> <span class="category1">var</span> flexUnitTester:FlexUnitTester;
            <span class="category1">public</span> <span class="category1">var</span> asynchronousTester:AsynchronousTester;
       }
}</pre>
</code>

</div></div> 
<br>
<strong>Theories</strong><br>
<br>
FlexUnit 4 introduces a whole new concept called theories.  A Theory as the name suggests allows you to create a test to check your assumptions in regard to how a test should behave.  This type of test is useful when you have a method you would like to test which can have large or even infinite sets of values.  The test takes parameters (data points) and these data points can be used in conjunction with the test.<br>
<br>
Create a new Test Suite and call it FlexUnit4TheorySuite.  <br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
package flexUnitTests
{
      <span class="category1">import</span> org.flexunit.assertThat;
      <span class="category1">import</span> org.flexunit.assumeThat;
      <span class="category1">import</span> org.flexunit.experimental.theories.Theories;
      <span class="category1">import</span> org.hamcrest.number.greaterThan;
      <span class="category1">import</span> org.hamcrest.object.instanceOf;
 
      [Suite]
      [RunWith("<span class="quote">org.flexunit.experimental.theories.Theories</span>")]
      <span class="category1">public</span> <span class="category1">class</span> FlexUnit4TheorySuite
      {
            <span class="category1">private</span> <span class="category1">var</span> theory:Theories;
  
            <span class="linecomment">//--------------------------------------------------------------------------</span>
            <span class="linecomment">//</span>
            <span class="linecomment">//  DataPoints</span>
            <span class="linecomment">//</span>
            <span class="linecomment">//--------------------------------------------------------------------------</span>
            
            [DataPoint]
            <span class="category1">public</span> <span class="category1">static</span> <span class="category1">var</span> number:<span class="category2">Number</span> = 5;
            
            <span class="linecomment">//--------------------------------------------------------------------------</span>
            <span class="linecomment">//</span>
            <span class="linecomment">//  Theories</span>
            <span class="linecomment">//</span>
            <span class="linecomment">//--------------------------------------------------------------------------</span>
            
              [Theory]
            <span class="category1">public</span> <span class="category1">function</span> testNumber( number:<span class="category2">Number</span> ):<span class="category1">void</span> 
            {
                  assumeThat( number, greaterThan( 0 ) );
                  assertThat( number, instanceOf(<span class="category2">Number</span>) );
             }
       }
}</pre>
</code>

</div></div> 
<br>
Add the test suite to the FlexUnit4.mxml:<br>
flexUnitCore.run( FlexUnit4Suite, FlexUnit4HamcrestSuite, FlexUnit4TheorySuite );
<br><br>
<strong>Testing User Interfaces </strong><br>
<br>
There is a tool called FlexMonkey (http://code.google.com/p/flexmonkey/) to test both the application visual appearance as well as the visual behavior. <br>
<br>
Up until FlexUnit 4 we didn&#8217;t have the ability to test user interfaces and MXML components weren&#8217;t an option when creating unit testing. <br>
<br>
FlexUnit 4 includes the concept of sequence so you can create sequences that includes all the operations you would like to perform on a UI.<br>
<br>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
package flexUnitTests
{
 	<span class="category1">import</span> flash.events.Event;
 	<span class="category1">import</span> flash.events.MouseEvent;
 	
 	<span class="category1">import</span> mx.controls.<span class="category2">Button</span>;
 	<span class="category1">import</span> mx.core.UIComponent;
 	<span class="category1">import</span> mx.events.FlexEvent;
 	
 	<span class="category1">import</span> org.flexunit.Assert;
 	<span class="category1">import</span> org.flexunit.async.Async;
 	<span class="category1">import</span> org.fluint.sequence.SequenceCaller;
 	<span class="category1">import</span> org.fluint.sequence.SequenceEventDispatcher;
 	<span class="category1">import</span> org.fluint.sequence.SequenceRunner;
 	<span class="category1">import</span> org.fluint.sequence.SequenceSetter;
 	<span class="category1">import</span> org.fluint.sequence.SequenceWaiter;
 	<span class="category1">import</span> org.fluint.uiImpersonation.UIImpersonator;
 
 	<span class="category1">public</span> <span class="category1">class</span> FlexUnit4CheckUITester
 	{
  		<span class="category1">private</span> <span class="category1">var</span> component:UIComponent;
  		<span class="category1">private</span> <span class="category1">var</span> btn:<span class="category2">Button</span>;
  		
  		<span class="linecomment">//--------------------------------------------------------------------------</span>
  		<span class="linecomment">//</span>
  		<span class="linecomment">//  Before and After</span>
  		<span class="linecomment">//</span>
  		<span class="linecomment">//--------------------------------------------------------------------------</span>
  		  
  		[Before(async,ui)]
  		<span class="category1">public</span> <span class="category1">function</span> setUp():<span class="category1">void</span> 
  		{
   			component = <span class="category1">new</span> UIComponent();
   			btn = <span class="category1">new</span> <span class="category2">Button</span>();
   			component.addChild( btn );
   			btn.addEventListener( MouseEvent.CLICK, <span class="category1">function</span>():<span class="category1">void</span> { component.dispatchEvent( <span class="category1">new</span> Event( '<span class="quote">myButtonClicked</span>' ) ); } )
   			
   			Async.proceedOnEvent( <span class="category1">this</span>, component, FlexEvent.CREATION_COMPLETE, 500 );
   			UIImpersonator.addChild( component );
   		}
  		
  		[After(async,ui)]
  		<span class="category1">public</span> <span class="category1">function</span> tearDown():<span class="category1">void</span> 
  		{
   			UIImpersonator.removeChild( component );			
   			component = <span class="category1">null</span>;
   		}				   
  		  
  		<span class="linecomment">//--------------------------------------------------------------------------</span>
  		<span class="linecomment">//</span>
  		<span class="linecomment">//  Tests</span>
  		<span class="linecomment">//</span>
  		<span class="linecomment">//--------------------------------------------------------------------------</span>
  		
  		[Test(async,ui)]
  		<span class="category1">public</span> <span class="category1">function</span> testButtonClick():<span class="category1">void</span> 
  		{
   			Async.handleEvent( <span class="category1">this</span>, component, "<span class="quote">myButtonClicked</span>", handleButtonClickEvent, 500 ); 
   			btn.dispatchEvent( <span class="category1">new</span> MouseEvent( MouseEvent.CLICK, <span class="category1">true</span>, <span class="category1">false</span> ) );
   		}
  		
  		[Test(async,ui)]
  		<span class="category1">public</span> <span class="category1">function</span> testButtonClickSequence():<span class="category1">void</span> 
  		{
   			<span class="category1">var</span> sequence:SequenceRunner = <span class="category1">new</span> SequenceRunner( <span class="category1">this</span> );
   			
   			<span class="category1">var</span> passThroughData:<span class="category2">Object</span> = <span class="category1">new</span> <span class="category2">Object</span>();
   			passThroughData.buttonLable = '<span class="quote">Click button</span>';
   			
   			<span class="category1">with</span> ( sequence ) 
   			{
    				addStep( <span class="category1">new</span> SequenceSetter( btn, {<span class="category1">label</span>:passThroughData.buttonLable} ) );
    				addStep( <span class="category1">new</span> SequenceWaiter( component, '<span class="quote">myButtonClicked</span>', 500 ) );
    				addAssertHandler( handleButtonClickSqEvent, passThroughData );
    				
    				run();
    			}
   			
   			btn.dispatchEvent( <span class="category1">new</span> MouseEvent( MouseEvent.CLICK, <span class="category1">true</span>, <span class="category1">false</span> ) );
   		}		
  		
  		<span class="linecomment">//--------------------------------------------------------------------------</span>
  		<span class="linecomment">//</span>
  		<span class="linecomment">//  Handlers</span>
  		<span class="linecomment">//</span>
  		<span class="linecomment">//--------------------------------------------------------------------------</span>
  				
  		<span class="category1">private</span> <span class="category1">function</span> handleButtonClickEvent( event:Event, passThroughData:<span class="category2">Object</span> ):<span class="category1">void</span> 
  		{
   			Assert.assertEquals( event.<span class="category2">type</span>, "<span class="quote">myButtonClicked</span>" );
   		}
  		
  		<span class="category1">private</span> <span class="category1">function</span> handleButtonClickSqEvent( event:*, passThroughData:<span class="category2">Object</span> ):<span class="category1">void</span> 
  		{
   			Assert.assertEquals(passThroughData.buttonLable, btn.<span class="category1">label</span>);
   		}		
  	}
}</pre>
</code>

</div></div> 
<br>
This is a few pages from the first draft of the "Advanced Flex 4" book coming out this year, <a href="http://www.amazon.com/AdvancED-Flex-4-Shashank-Tiwari/dp/1430224835/ref=sr_1_3?ie=UTF8&s=books&qid=1243345109&sr=1-3">click here</a> to learn more.<br>  Please keep in mind that this is not a final version and the pages weren't tech reviewed or proofed yet.]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2060621</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2060621" />
    <title>Comment from Chris Luebcke on 2009-05-28</title>
    <author>
        <name>Chris Luebcke</name>
        <uri>http://www.roundpeg.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.roundpeg.com">
        <![CDATA[<p>This is really a great addition, and a great write-up. Discovering flunit was like a breath of fresh air after having struggled with FlexUnit for a year or better before that. It's nice to see Flex unit testing really maturing.</p>]]>
    </content>
    <published>2009-05-29T00:10:16Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2060671</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2060671" />
    <title>Comment from Saurabh Narula on 2009-05-29</title>
    <author>
        <name>Saurabh Narula</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Elad,</p>

<p>The writeup is spot on, thanks for putting it up.</p>

<p><br />
Saurabh Narula</p>

<p><br />
</p>]]>
    </content>
    <published>2009-05-29T15:12:10Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2060900</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2060900" />
    <title>Comment from Samuel Asher Rivello on 2009-06-02</title>
    <author>
        <name>Samuel Asher Rivello</name>
        <uri>http://RivelloMultimediaConsulting.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://RivelloMultimediaConsulting.com">
        <![CDATA[<p>This feature looks great.  For more information about this and all the features of Flex 4 and Flash Builder 4, see this upcoming class by Rivello Multimedia Consulting; <a href="http://www.blog.rivello.org/?p=324">http://www.blog.rivello.org/?p=324</a></p>]]>
    </content>
    <published>2009-06-02T16:10:26Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2070083</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2070083" />
    <title>Comment from StanB on 2009-08-10</title>
    <author>
        <name>StanB</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>I'm not able to find how to structure a project the will have my Flex app, test and the test runner in the same Eclipse project.  It seems, an Flex project in Eclipse, using Flex Builder can have only one main app.  So, it's either my application or the test runner.  How do I solve this problem?  It seems an simple issue and people must have solved it if they use flexunit for their production development, but I'm not sure how to do it.</p>]]>
    </content>
    <published>2009-08-10T16:39:07Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2070371</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2070371" />
    <title>Comment from Patrick Groves on 2009-08-14</title>
    <author>
        <name>Patrick Groves</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>The range error test isn't set up correctly.</p>

<p>  [Test(expected="RangeError")]<br />
  public function rangeCheck():void<br />
  {<br />
        var child:Sprite = new Sprite();<br />
        child.getChildAt(0);<br />
  }</p>

<p>Above, this will always throw an exception, as no children have been added to the sprite instance. Changing the index will have no effect.</p>

<p>Just add something like a button instance to the sprite.</p>

<p>  [Test(expected="RangeError")]<br />
  public function rangeCheck():void<br />
  {<br />
       var sprite:Sprite = new Sprite();<br />
       var button:Button = new Button();<br />
            <br />
       sprite.addChild(button);            <br />
       sprite.getChildAt(0);<br />
  }</p>

<p>An exception will not be thrown when the index is 0.</p>]]>
    </content>
    <published>2009-08-14T08:48:45Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2144394</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2144394" />
    <title>Comment from Elad Elrom on 2009-10-17</title>
    <author>
        <name>Elad Elrom</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Patrick,</p>

<p>The idea of the test was to show how the metadata works.  </p>

<p>The method will always success since it's expecting an error and that's the idea of the test that has the expected error metadata.  If the test doesn't get an error it fails.  Feel free to copy the code and you can see that you always get a 'green' light since it will produce an error.  I am showing examples, but feel free to play around and change them :)</p>

<p>Cheers,<br />
Elad Elrom</p>]]>
    </content>
    <published>2009-10-18T01:37:30Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2148616</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2148616" />
    <title>Comment from Rani on 2009-10-20</title>
    <author>
        <name>Rani</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>"I'm not able to find how to structure a project the will have my Flex app, test and the test runner in the same Eclipse project. " </p>

<p>The tests are recommended to be created in a separate folder. One can decide to do this under the src folder or in a separate souce folder added to the project. (Flash builder Project-> Properties -> Build Path -> SourcePath). </p>

<p>What is menat by main application. (Default applicaiton ? ) Flex Project can have only one default application, but many applications are allowed. Using executeFlexUnit tests option ( 1. (Run, Debug, Profile -> FlexUnit tests) , 2. Right click on the project explorer, 3. Short keys etc in the Flash Builder will pick up appropriate application and launch the same. ). It need not be the default application</p>

<p>If you have more querries regarding FlexUnit usage in FlashBuiler (beta2), please contact us at ranik@adobe.com</p>]]>
    </content>
    <published>2009-10-21T04:38:13Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2152271</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2152271" />
    <title>Comment from Debabrata Acharjee on 2009-10-23</title>
    <author>
        <name>Debabrata Acharjee</name>
        <uri>http://debabrataa.blogspot.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://debabrataa.blogspot.com">
        <![CDATA[<p>Thanks for the article. A must read for all flex developers who are going to use FlexUnit 4.</p>]]>
    </content>
    <published>2009-10-23T14:20:35Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36333-comment:2166547</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36333" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/flashbuilder4-will-support-fle.html#comment-2166547" />
    <title>Comment from Patrick Groves on 2009-11-01</title>
    <author>
        <name>Patrick Groves</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Elad,</p>

<p>You mentioned that...</p>

<p>"Let’s take a look at the example below. The rangeTest method creates a new Sprite object and tries to get the children at index 0 which exists so we will not get an error message and the test will fail. To get a success method, change the child.getChildAt( 1 ); Since child at index 1 doesn’t exist, the exception will be raised and the test will pass:</p>

<p>var child:Sprite = new Sprite( );<br />
child.getChildAt( 0 );..."</p>

<p>The child at index 0 doesn't exist with the aforementioned code, which throws an exception and the test actually passes, where your intention was for it to fail. That's why I ammended the method so that changing the index will toggle a pass/fail outcome.</p>

<p>Patrick</p>]]>
    </content>
    <published>2009-11-01T08:00:04Z</published>
  </entry>

</feed
