Dec
02
Filed Under (General) by Ryan Christiansen on 12-02-2007

FlexUnit Implementation

public class TestExecute extends TestCase
{
   public static function getSuite() : TestSuite
   {
      var suite : TestSuite = new TestSuite();
      suite.addTest(new TestExecute("testGetString"));
      suite.addTest(new TestExecute("testExecuteNull"));
 
      return suite;
   }
 
   public override function setup() : void
   {
      CustomClass.setString("TestString");
   }
 
   public function testGetString() : void
   {
      // sample code to test
      Assert.assertEquals( CustomClass.getString(), "TestString");
   }
 
   public function testExecuteNull() : void
   {
      try
      {
         // sample code to test
         CustomClass.execute( null );
      }
      catch ( e:ArgumentError )
      {
         // exception thrown correctly
         return;
      }
      catch ( e:Error )
      {
         // exception thrown but of wrong type
         throw new AssertionFailedError("Invalid exception.");
      }
 
      // no exception was thrown
      throw new AssertionFailedError("Uncaught exception");
   }
}

FUnit Implementation

[TestFixture]
public class TestExecute
{
   public static function getSuite() : TestSuite
   {
      var suite : TestSuite = new TestSuite();
      suite.add(TestExecute);
 
      return suite;
   }
 
   [SetUp]
   public function setup() : void
   {
      CustomClass.setString("TestString");
   }
 
   [Test]
   public function getString() : void
   {
      // sample code to test
      Assert.areEqual( CustomClass.getString(), "TestString");
   }
 
   [Test]
   [ExpectedError("ArgumentError")]
   public function executeNull() : void
   {
      // sample code to test
      CustomClass.execute( null );
   }
}

Key Differences:

  • No need to extend the TestCase base class
  • Tests are marked with the [Test] metadata tag
  • No “test” prefix is required for TestCase methods to be reflected
  • Expected failures are easily marked with an [ExpectedError] tag
  • Supports SetUp, TearDown, FixtureSetUp, and FixtureTearDown
  • SetUp is marked with the [SetUp] tag – No override needed
  • Advanced Collection and String assertion support
  • and much more…
Bookmark and Share


Comments:
2 Comments posted on "How does FUnit compare with FlexUnit?"
Amrish Jaiswal on July 8th, 2008 at 6:43 am #

How can we create and store unit test result of flex as report?


Ryan Christiansen on July 8th, 2008 at 7:30 am #

The XmlResultWriter is currently about 80% complete. I will forward some of the details and notify you directly when ready for use.


Post a comment

Name: 
Email: 
URL: 
Comments: 

.