Quantcast
Channel: Adobe Community : Popular Discussions - FlexUnit
Viewing all articles
Browse latest Browse all 25673

How to create a TestRunner for FlexUnit 4?

$
0
0

I just started with FlexUnit 4 today and can already see the benefit of all of the new features.  I am a bit stumped on how to get the initial setup to work.  As far as I can tell, most of the tutorials, walkthroughs, installation instructions linked to from the Adobe site are for earlier versions of FlexBuilder, or they reference classes that don't exist in the version I just downloaded.  Can someone help me access these new features?

 

I created a test case that does not extend any base classes and uses hamcrest matchers.  Here is an excerpt:

 

public class RangeHashMapTest

{

  private var map:RangeHashMap;


 

  [Before]

  public function setup():void {

    map = new RangeHashMap(0, 50);

    map.put(6, "a");

  }


 

  [Test]

  public function testPut_Valid():void {

    map.put(5, "foo");

    assertThat("foo", equalTo(map.getValue(5)));

  }


  [Test(expects="TypeError")]

  public function testPut_invalid():void {

      map.put("a", "foo");

  }


 

  [Test]

  public function testGet():void {

    assertThat(map.getValue(-10), isA(nullValue()));

  }

}

 

I then created a TestRunner based on the FlexUnit walkthrough link on the Developer Documentation section of the FlexUnit 4 site:

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"

        xmlns:flexunit="flexunit.flexui.*"

        creationComplete="onCreationComplete()">

 

  <mx:Script>

    <![CDATA[

      import com.ericfeminella.collections.RangeHashMapTest;

      import flexunit.framework.TestSuite;

     

      // Create the test suite and run the tests

      private function onCreationComplete():void

      {

          testRunner.test = createSuite();

          testRunner.startTest();

        }

     

      // Creates the test suite to run

      private function createSuite():TestSuite {

          var testSuite:TestSuite = new TestSuite();

         

          testSuite.addTestSuite( RangeHashMapTest );

         

          return testSuite;

        } 

    ]]>

  </mx:Script>


  <!-- FlexUnit GUI Component -->

  <flexunit:TestRunnerBase id="testRunner" width="100%" height="100%" />

</mx:Application>

 

When I run this, I get an Error:

"Type Coercion failed: cannot convert ...:RangeHashMapTest@4c6e661 to flexunit.framework.Test."

 

I tried to have my test extend TestCase, and it ran successfully, but all of the tests fail, because the [Before] never gets executed, so map is always null.  It also says that all of my tests have no asserts.  It seems as though I am using the new code, but not able to take advantage of the new features.

 

Thanks!

Brian


Viewing all articles
Browse latest Browse all 25673

Trending Articles