Asked By
alex baker
30 points
N/A
Posted on - 12/12/2013
I am learning how to unit test with mock objects in Action Script 3.0. I was able to create and instantiate the Mock objects but cannot go about defining their behaviour. Can any expert guide me what code or script to use to do that? Also tell me how to go on about verifying the behaviour and checking if I have done correctly?
Unit test with mock objects in Action Script 3.0
First you need to invoke the Mock’s API’s “expects()” method to verify if your Mock have been set to your expectations.
Methods used in invoking APIs
· expects (methodName:String) – tells the expected name of method call
· times (numOfTimes:int) – Sets the no. of times a particular method on how it should be called
· withArgs (arg1, arg2, arg3,…..arg(x)) – tells the mock of what arguments that should passed to a particular method
These will then return a reference to the Mock to do your expectations, then chain the methods for readability.
For example: set Mock to expect [translate (“English”, “Portuguese”,”Hello”)] to be called once then you can use this syntax:
Then set the behavior of your Mock objects. Use the willReturn() method to verify how an object would reacts to invalid data.
I’m assuming you know how to inject and exercise SUT, let’s go to verification
I believe you can take it from here.