i have been working on how handle inherited flexunit test beginning fail on faster server builds. mymockservice not getting prepared before unit test begins run. using flexunit , mockolate.
<failure message="a proxy com.something.somemock.service::mymockservice has not been prepared yet" type="com.something.somemock.myasynctest">argumenterror: proxy com.something.somemock.service::mymockservice has not been prepared yet. //... (lots removed here) </failure>
generic imports being used:
import flash.events.event; import flexunit.framework.assert; import mockolate.nice; import mockolate.prepare; import mockolate.stub; import mockolate.verify; import org.flexunit.async.async; import flash.utils.timer; import flash.events.timerevent;
here's stub of code. (i think) important parts there gist.
public class myasynctest { [before(async)] public function preparemockobjects():void { async.proceedonevent(this, prepare(mymockservice), event.complete); } [test(async)] public function testexecute():void { var service:mymockservice = nice(mymockservice); verify(service).method("runsomething").args(argumentbuilder).once(); } }
after doing lot of work changing timeouts , adding sleep methods (all useless in battling error) have introduced 1 more test flexunit test class contains delay. ordered tests , finding test passes every time. (this good) hate putting test in 3 second delay need prepare finish.
here's code stub visuals:
public class myasynctest { protected function makemesleep(howlongms:int):void { //timer code sleep } [before(async)] public function preparemockobjects():void { async.proceedonevent(this, prepare(mymockservice), event.complete); } [test(async, order=1)] public function delaythenexttest():void { var haspaused:boolean = makemesleep(3000); assert.asserttrue("this silly delay allow service prepare", true); } [test(async, order=2)] public function testexecute():void { var service:mymockservice = nice(mymockservice); verify(service).method("runsomething").args(argumentbuilder).once(); } }
i'm glad have test build should, feels dirty. has been assumption [test] block not run until [before] block has finished doesn't seem case in testing condition. guess 1 important take away folks me whether test in poor style way mock service being prepared, , better way avoid adding "sleep" test buy time? (poor style in , of imho)
thanks input in advance.
i have run similar issues mockolate, , seem remember reading answer drew mentioned aware exist.
i have found rules reliable async tests, , using them makes code more readable, well. declare both mockolaterule , desired mock objects member variable (must public metadata picked correctly, , make sure instantiate rule!), use mock()
nice()
otherwise.
[rule] public var myrule:mockolaterule = new mockolaterule(); [mock] public var myservice:myservice; [before] public function setup():void { myservice = mock(myservice); } [test] public function test():void { assertnotnull(myservice); }
Comments
Post a Comment