zondag 24 februari 2008

FlexUnit and Flex3

Since Flex3, some basic actionscript logic has changed which prevents the FlexUnit framework 0.85 (as it is available on Google Code) to find the test methods automatically. This is caused by the fact that since flex 3, for each does no longer iterate over the methods in an object.
I fixed the problem by creating an own TestCase class, which subclasses from the original one. In here, we override the getTestMethodNames function to work with DescribeType instead of for each.
This is also done in as3mock.

Here is what it looks like:


public override function getTestMethodNames():Array
{
var methodNames:Array = new Array();
var typeDesc:XML = describeType(this);
var item:XML;
for each (item in typeDesc.elements("method")){
var att:XML;
for each (att in item.attribute("name")){
var name:String = att.toXMLString();
if (0 ==name.indexOf("test")){
methodNames.push(name);
}
}
}
return methodNames;
}