Skip to content

Instantly share code, notes, and snippets.

@Stray
Created December 4, 2010 16:46
Show Gist options
  • Save Stray/728312 to your computer and use it in GitHub Desktop.
Save Stray/728312 to your computer and use it in GitHub Desktop.
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.
Thanks!
Stray
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) {
super(methodName)
}
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);
addChild(robotEyes);
robotEyes.visible = false;
appendTests();
// need to wait a while
var timer:Timer = new Timer(1000,1);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
private function timerHandler(e:TimerEvent):void{
robotEyes.visible = true;
super.run();
}
override protected function cleanUp():void{
removeChild(robotEyes);
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);
runNextEndToEndTest();
}
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());
getResult().run(nextTest);
}
else
{
dummyDispatcher.dispatchEvent(new Event(Event.COMPLETE));
}
}
private function application_tests_complete(e:Event = null):void
{
// just to make the async keep the test alive
}
}
}
@Stray
Copy link
Author

Stray commented Dec 5, 2010

Oh! Sorry ... duh :)

Yes - game repo is at https://github.com/Stray/robotlegs-demo-StrategyGame

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!

@newtriks
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: https://github.com/newtriks/RobotEyes/tree/flex

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