Stanislav Zorjan - Stasha - Full Stack Software Engineer and Game Development Hobbyist - Prague

In this post I will show you very basic example how to use FlexUnit framework in both Flash Builder Basic and Professional.

First you'll have to download FlexUnit framework.
You can download it from:
(In this example I am using FlexUnit 4.1)

When you download FlexUnit, extract it and find libraries:

(you may have different versions) 

Create new flex project "App", create "application" package and move "App.mxml" to "application" package. Then copy two "FlexUnit" files to your project "libs" directory.

Inside "src" folder, create another package "applicationTest". This is main package for holding everything regarding FlexUnit. 

Now inside "applicationTest" package, create package "_suites_".  I named it "_suites_" just to be at the first place in "package explorer", but you are free to name it whatever you like. In "_suites_" package we are going to store "test suites" and test runner application. All other packages and files, except "_suites_" package, are going to reflect "application" package structure.

Now create "RunTests.mxml" application and "" files and put them inside "applicationTest->_suites_" package.
"RunTests" application is main application for running tests, so whenever you need to run tests, you will run "RunTests" application.
"AppTestSuite" is collection (organization unit) of tests thus it will hold our simple "AppTest test".

Because our tests are reflecting "application" package structure, create "" class and put it inside "ApplicationTest" package.
"" is test class thus it should hold tests for testing all "units" methods presented in "App.mxml"  
You can name your test classes whatever you want, but if your test class has completely different name from class you are testing, than I hope you know what you are doing.


At this point your project structure should look like this:



Now, after successfull structure creation, here is source code for each file:






package applicationTest._suites_
	import applicationTest.AppTest;
	public class AppTestSuite {
		public var appTest:AppTest;

package applicationTest {
	import application.App;
	import flexunit.framework.Assert;
	import org.flexunit.async.Async;
	public class AppTest {
		public static var app:App;
		public function AppTest() { }
		public static function construct():void{
			app = new App();
		public static function destroy():void{
			app = null;
		public function setUp():void {
		public function tearDown():void {
		public function appCreated():void{
			app.testProperty = true;
			Assert.assertEquals(app.testProperty, true);


When you run "RunTests" application, you should see in your browser something like this:



and if tests fail, you will see:



Now that you know how to run simple test, you are ready to push it to a higher level.

You can learn more about FlexUnit at:

Comments (0)