Skip to content

Instantly share code, notes, and snippets.

Created December 4, 2010 16:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
How should I go about this in asunit 4?
I'm growing an end-to-end test which has more steps to it than my
usual end-to-end tests.
As a result I'd like to split my test-stages into separate test cases
(or something similar - could be helper classes of some kind)
and run them in a specific order.
The test cases follow on from each other - that is, they pick the
application up in the state it was in at the end of the previous test,
and then move it forward and verify that everything is working up to that point.
I tried implementing this in asunit3 but I've found that
beyond the first test case the tests don't really run.
If I switch to asunit 4 can I inject the same instance into each
test case, and can I control the order the test cases run in,
other than alphabetically?
The code below is what I've set up in asunit3. The child test case
run first (the one added in line 21) does run properly. The one added
afterwards doesn't. Obviously I *could* just not null out the RobotEyes
instance, as it is actually static... but that feels a bit gross.
package strategy.xendtoendtests {
// imports removed for brevity
public class PyramidGameEndToEndTest extends TestCase {
private var robotEyes:RobotEyes;
private var config:IGameConfig;
private var endToEndTests:Vector.<Class>;
private var runningEndToEndTests:Boolean;
private var dummyDispatcher:EventDispatcher = new EventDispatcher();
public function PyramidGameEndToEndTest (methodName:String=null) {
private function appendTests():void
// each of these is a test case in itself, but it should report
// its results back into this test
endToEndTests = new Vector.<Class>();
endToEndTests.push( StartingConditions );
endToEndTests.push( FirstStoneSupplyOffer );
// and further stages of the end-to-end test,
override public function run():void{
config = new FirstGameConfig();
robotEyes = new RobotEyes(PyramidGame);
robotEyes.visible = false;
// need to wait a while
var timer:Timer = new Timer(1000,1);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
private function timerHandler(e:TimerEvent):void{
robotEyes.visible = true;;
override protected function cleanUp():void{
robotEyes = null;
public function testEndToEnd():void {
// this async is only to keep the test alive while
// all the child testcases run
var handler:Function = addAsync(application_tests_complete, 20000);
dummyDispatcher.addEventListener(Event.COMPLETE, handler);
private function prepareTest(testClass:Class):TestCase {
var nextTest:TestCase = new testClass() as TestCase;
nextTest['onTestComplete'] = runNextEndToEndTest;
nextTest['config'] = config;
nextTest['robotEyes'] = robotEyes;
return nextTest;
private function runNextEndToEndTest():void
if(endToEndTests.length > 0)
var nextTest:TestCase = prepareTest(endToEndTests.shift());
dummyDispatcher.dispatchEvent(new Event(Event.COMPLETE));
private function application_tests_complete(e:Event = null):void
// just to make the async keep the test alive
Copy link

Stray commented Dec 5, 2010

Oh! Sorry ... duh :)

Yes - game repo is at

In the interests of full disclosure:

  • It's a project for a client. We provide their e-learning platform and content and it's an immersive learning exercise in project management that sits within an "introduction to project management" lesson.
  • But the client is pro open-source so when we develop something generic they are happy for us to share it.

So - dig in!

Copy link

I have (as Stray knows) just ported RobotEyes for use in Flex and written an end to end test case using ASUnit4. Keep an eye here for example link:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment