|
|
Resources
This page contains articles, tutorials and other resources on how to work with the FlexUnit ActionScript Unit Testing framework.
Articles / Tutorials
- none yet
External Resources
- Getting Started with FlexUnit Darron Schall
- Using FlexUnit with Ant Peter Martin
- Advanced ActionScript 3 with Design Patterns Book Chapter 1 includes a section on how to setup FlexUnit and write your first test.
- AIRRunner Desktop based application for running unit tests. (supports FlexUnit).
Sign in to add a comment

I wrote a Hello World for FlexUnit?. You can find it at: http://helloopensource.org/FlexUnit
also see http://blog.iconara.net/2007/02/06/flexunit/
Also: http://www.adobe.com/devnet/flex/articles/unit_testing.html
Here's a link to Google Group for discussions: http://groups.google.com/group/as3flexunitlib
Has anyone had any luck getting FlexUnit? to work with continuous integration tools (for example, CruiseControl?)?
Re Continuous Integration, have you seen AIRRunner?
Hi Mark, We are doing this using antennae http://code.google.com/p/antennae/ We use Hudson for constant integration but this is essentially an Ant based solution and would certainly work on Cruise Control.
Hi. I wrote an utility class to simplify the configuration of a flexunit testsuite. All methods starting with "test" are added automatically as test cases when the suite is created in the following way:
private function createSuite():TestSuite? {
}The ReflectiveTestCase? uses reflection to read all "test" methods. In this way you will never forget to add your tests to the suite!
package mypackage {
}It would be nice if flexunit.framework.Assert had a assertThrows and a assertDoesNotThrow function.
Here is my implementation, which can be added to flexunit.framework.Assert (need to recompile the SWC file to use this), or just add this to a custom class that extends flexunit.framework.TestCase?, and have your test cases extend the new class:
/** * Test if a function call throws a certain exception when called with the given parameters. Fail if it does not. * * @param userMessage A string containing a custom message that will be displayed along with the system message when the test fails. * @param errorType A class (not an instance) derived from <code>Error</code>. The type of error we are expecting not to be thrown. * @param thisArg A reference to the object that will be <code>this</code> in the context of the function call (can be null). * @param fnct A reference to the function to be tested. * @param args An array of the arguments to be used forthe function call. */ public static function assertThrows( userMessage:String, errorType:*, thisArg:Object, fnct:Function, args:Array ):void { var caughtErrType:String = "none"; try { fnct.apply( thisArg, args ); } catch(e:Error) { // if catching the requested type (or derived from), test passes if ( e is errorType ) return; // caught something but not what was expected caughtErrType = e.name; } // got here if the test fails var failMsg:String = "expected: " + errorType.toString() + " but threw: " + caughtErrType; failWithUserMessage( userMessage, failMsg ); } /** * Test if a function call throws a certain exception when called with the given parameters. Fail if it does. * * @param userMessage A string containing a custom message that will be displayed along with the system message when the test fails. * @param errorType A class (not an instance) derived from <code>Error</code>. The type of error we are expecting not to be thrown. * @param thisArg A reference to the object that will be <code>this</code> in the context of the function call (can be null). * @param fnct A reference to the function to be tested. * @param args An array of the arguments to be used for the function call. */ public static function assertDoesNotThrow( userMessage:String, errorType:*, thisArg:Object, fnct:Function, args:Array ):void { try { fnct.apply( thisArg, args ); } catch(e:Error) { // if catching the requested type (or derived from), test fails if ( e is errorType ) { var failMsg:String = "Threw: " + errorType; failWithUserMessage( userMessage, failMsg ); } } }Note that if you create a custom class, you must implement failWithUserMessage, as it is private to flexunit.framework.Assert. Here is my implementation:
/** * Cause test to fail, format message * * @param userMessage A string supplied by the caller of the assertion * @param failMessage A string supplied by assertion test function */ private static function failWithUserMessage( userMessage:String, failMessage:String ):void { if ( userMessage.length > 0 ) failMessage = userMessage + " - " + failMessage; fail( failMessage ); }Please take a look on how to test for exception in the junit project