|
From: Matt F. <mat...@gm...> - 2005-11-13 00:28:33
|
Hey Luke, Thanks for your reply. >> events in AS 3.0 fire synchronously, so I usually test them by triggering the event and >> then checking the state of the object in a regular TestCase. The approach I have been using sounds the same: 1) In my TestCase I write a test designed to test the state of the object after an Event has fired. 2) In my Testcase I override the run method and trigger the event (subscribing to it) 3) In the event handler I call super.run(); The problem I find with this approach is that if the event doesn't fire (for whatever reason) then super.run() is never called and hence no tests run/no tests fail! In larger projects when you have perhaps 100s of tests it becomes harder to track the exact number of tests expected to run. Hence you can be in a situation when all your tests appear to be passing, but in reality all your tests aren't running. I have experimented with including timeout checks (to test whether the event fired) however I find this to be pretty messy and generally find that the TestCases don't scale particularly well in such when this is implemented. Do you also find this a problem? >> Mock Objects are also useful when testing abstract classes I had actually been using Concrete implementations of Abstract Classes designed specifically for testing purposes, so this seems to fit with the description of Mock Objects. Thanks for all the info Cheers Matt On 11/13/05, Luke Bayes <lb...@gm...> wrote: > Hey Matt, > > Thanks for the kind words! > > I'm really glad to hear that someone got the XUL UI and AsUnit 3.x up an= d > running! > > > > I wondering if the new Event Model in AS3, with its bubble nature > > will make it easier to test event based code? > > That's actually a very good idea, I haven't really messed with the bubbl= e > feature much yet... If you get something going like that, I would love to > see it. > > As far as using AsynchronousTestCase to test event based code, I'm not s= ure > that's really the best way because events in AS 3.0 fire synchronously, s= o I > usually test them by triggering the event and then checking the state of = the > object in a regular TestCase. > > We created the AsynchronousTestCase and Example because there are occasi= ons > where we wanted to test functionality that isn't compiled into the swf fi= le. > EG: Loaders and Sockets. > > This actually leads nicely into your next question: > > > > Also can you please explain the nature of Mock Object Test Cases - and > > when we might choose to use one? > > Generally, when you want to test an object that consumes asynchronous > functionaliy (like the client of a Socket connection), you should typical= ly > build a Mock Object of the Socket and use that instead of the Socket itse= lf. > This is different from testing the Socket. As mentioned before, an > AsynchronousTestCase would be used to validate the Socket, but then a > SocketMock would be used to test it's clients. > > http://c2.com/cgi/wiki?MockObject > > Mock Objects are also useful when testing abstract classes. Of course AS > 3.0 doesn't natively support the abstract keyword, but we have been > implementing abstract classes by throwing an error in the constructor, th= en > using a Mock object to validate it's functionality. > > Thanks, > > Luke Bayes > www.asunit.org > > > |