Skip to main content

Using FlexUnit for Stress Testing

I saw quite a few questions in the forums on how to stress
test a Flex application. I thought about it and came up with an idea
that I want to share here.

I think FlexUnit can be used for stress testing. It is not
that difficult. I simply add multiple test runners for each client
application and run all of them asynchronously. Here is the example of
the FlexUnit runner:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" xmlns="*"

import flexunit.framework.TestSuite;
import test.TemperatureConverterTest;
import test.ArrayUtilTest;
import mx.collections.ArrayCollection;
import flexunit.flexui.TestRunnerBase;

public var testClients:ArrayCollection;

public var NUMBER_OF_TESTS:int = 100;

private function onCreationComplete():void
var clients:Array = new Array();
var i:int;
for (i = 0; i < NUMBER_OF_TESTS; i++) {
testClients = new ArrayCollection(clients);

// Creates the test suite to run
private function createSuite():TestSuite {
var ts:TestSuite = new TestSuite();

ts.addTest( TemperatureConverterTest.suite() );
ts.addTest( ArrayUtilTest.suite() );

return ts;

private function startTests():void {
trace(" elements: " + testRepeater.numChildren);
var tests:Array = this.test as Array;
for each (var testRunner:TestRunnerBase in tests) {
testRunner.test = createSuite();


<mx:Button name="Run" label="Start Tests" click="startTests()" />

<mx:Panel layout="vertical" width="100%">
<mx:Repeater id="testRepeater" dataProvider="{testClients}">
<flexunit:TestRunnerBase id="test" width="100%" height="100%" />


Here is a screen shot of the test with 100 test runners:

So, I guess once you have a client application that runs
hundreds of tests in parallel, it is easy to launch it on several
instances of the browser, or even on several PCs. All you need to do is
to add startTests() call to onCreationComplete() as a last
line of the method, deploy the app and simply open the URL in the

The other nice thing about it is that this test client can be
used for profiling purposes. FlexBuilder has a very nice profiler. I
found it very helpful in testing my BlazeDS application.


Very interesting - and I have two questions:

1. I'd be interested in reading more details on what the unit tests you are running do. I'm thinking that if I were to use this approach it wouldn't be for actual "unit" testing - i.e. testing relatively small pieces of code - instead I'd be doing something more extensive - for example testing calls across the wire to my DB via BlazeDS. Is this what you do?

2. I'm assuming that when you talk about using the profiler, you mean that you're running the profiler when you're simultaneously running all the tests. Is this correct?



PS I'm linking to this at my "testing-debugging-agile-methods" page:
Mykola said…
Hi Douglas, Thank you for your comment. The example test cases in this post are pure unit tests. However, I agree with you, FlexUnit is a great tool for integration tests as well. I added a new post today that describes testing BlazeDS data services with FlexUnit. Here is a link:

The FlexUnit test runner is a regular Flex application. I.e. it can be profiled as any other Flex application. So, it is correct, I am running the profiler when I run tests. The profiling reveals more problems when the application is under load.

Thanks for the link to your site! It has lots of info on testing and tools.
Thanks for the response, Mykola, and for the new article. Interesting stuff. BTW, are you aware of dpUint (

Thanks for sharing about your way making stress testing.

I really like the way your post looks! Nice presentation of your thoughts!

Anonymous said…
I have a question about the FlexUnit running in Flash. It is my understanding (and please correct me if I'm wrong) that the FlashPlayer only has 1 thread. So wouldn't all your test cases actually be from 1 thread? So the load you can handle might be much different then what you're actually showing here?
Anonymous said…
Can u pls add the code for ArrayUtilTest too . Since i am new to FLEXUNIT i am not able to point out
how to write that one .

import test.ArrayUtilTest;
ts.addTest( ArrayUtilTest.suite() );
Mykola said…
package test
import flexunit.framework.TestCase;
import flexunit.framework.TestSuite;
import mx.utils.ArrayUtil;

public class ArrayUtilTest extends TestCase
public function ArrayUtilTest(methodName:String)
super( methodName );

public static function suite():TestSuite {
var ts:TestSuite = new TestSuite();

ts.addTest( new ArrayUtilTest( "testToArray" ) );
ts.addTest( new ArrayUtilTest( "testToArrayArray" ) );
ts.addTest( new ArrayUtilTest( "testToArrayNull" ) );
return ts;

* If the Object is already an Array, it returns the object.
public function testToArrayArray():void {
var o:Array = new Array();
o.push("This is a test");
o.push("Some string");
var result:Array = ArrayUtil.toArray(o);
assertTrue(result != null);
assertTrue(result.length == 2);
assertTrue(result[0] == o[0]);
assertTrue(result[1] == o[1]);

* If the Object is already an Array, it returns the object.
* If the object is not an Array, it returns an Array in which the only element is the Object.
* As a special case, if the Object is null, it returns an empty Array.
public function testToArray():void {
var o:Object = new String("Hello world");
var result:Array = ArrayUtil.toArray(o);
assertTrue(result != null);
assertTrue(result.length == 1);
assertTrue(result[0] == o);

* As a special case, if the Object is null, it returns an empty Array.
public function testToArrayNull():void {
var o:Object = null;
var result:Array = ArrayUtil.toArray(o);
assertTrue(result != null);
assertTrue(result.length == 0);


Popular posts from this blog

cucumber-jvm and Android Studio

During this Winter holidays, I've been exploring a Behavior Driven Development and experimented with a couple of testing frameworks: Calabash and cucumber-jvm.

In this post, I would like to describe setting up cucumber-jvm for Android Studio projects.

I've extended cucumber-jvm examples with a version for Android Studio. Here is a copy in my github branch:

In addition to the example code, here is some details on how it was created.

The cucumber-jvm requires several libraries to be added to a project:

I've found it's easier to add those dependencies with the Android Studio project setup dialog because it takes care of the jar versions for you.

File > Project Structure > Modules > app > Dependencies > + > Library dependency
  > type "cucumber" in the s…

Building a Flex project with Ant

Here is a quick sample on how to build a simple Flex
"hello world" project with Ant. The "hello world" project contains a src folder with one Flex application file and an Ant build.xml file:


The app.mxml is the main module of the project. It simply has a label with a "Hello World!" text:<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
<mx:Label text="Hello World!"/>
Here is the build.xml source:
<?xml version="1.0"?>
<project name="fx_practice7" default="all">

<!-- Init the build process -->
<target name="init" unless="initialized">
<!-- Name of project and version -->
<property name="FLEX_HOME" location="/Users/mykola/java/flex"/>

<property na…