Created
December 4, 2010 16:46
-
-
Save Stray/728312 to your computer and use it in GitHub Desktop.
How should I go about this in asunit 4?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
I saw the RobotEyes repo. Is your game project's source available? Or is it private?
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!
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
Excellent - thanks Ben! I was just checking out Melomel + Cucumber and I think at the moment it's not fine-grained enough for me on the non-flex side. Also, with RobotEyes is that you can listen for events to use as cues, which I have found to be pretty useful when you're picking up async stuff etc where timings are variable. AS3 doesn't have the busy cursor (afaik).
It's open source - repo is at: https://github.com/Stray/RobotEyes
I've added some more functionality since I last pushed - the nice thing about it being actionscript is that it's very, very simple to extend as your tests require something new. I'll add all my changes to the repo today.
Oddly the broken-down-tests thing is actually working really nicely now in asunit 3 - just using a really primitive approach of having a static instance of the application running in the RobotEyes master class, and using alphabetical naming to keep my tests in order. Crude but it's not getting in my way right now, so I can focus on the detail of what I'm testing.
So - as these tests are part of an open-source 'TDD a strategy game using robotlegs' thing, I'll do it all in this slightly dirty way, and then refactor to Cucumber / Melomel + RobotEyes afterwards because that'll be a really good learning path I think, and will produce something useful in terms of a complete "how" in asunit and then in Cucumber+Melomel as well.
It also potentially highlights where you'd want to switch from in-suite end-to-end testing to external end-to-end testing. If there are pain points then I'm sure I'll hit them :)