Archive for December, 2007

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

FUnit is the first generation of xUnit based unit-testing tool to leverage the custom metadata capabilities of the Flex mxmlc compiler. FUnit is comparable to patterns observed in NUnit, and carries with it a widely adopted framework API with tightly integrated strong-typed metadata and other reflection related capabilities.

The tag-based attribute model of FUnit makes it the most intuitive unit-testing framework ever created for the Flex platform.



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…


.