comparison bindings/as3/ext/asunit/framework/TestCaseExample.as @ 732:3a0b9700b3d2

* Initial AS3 commit
author mas01mj
date Tue, 14 Sep 2010 16:47:10 +0000
parents
children
comparison
equal deleted inserted replaced
731:65134dd772fc 732:3a0b9700b3d2
1 package asunit.framework {
2 import asunit.framework.TestCase;
3 import flash.display.Sprite;
4 import flash.events.Event;
5 import flash.events.IEventDispatcher;
6 import flash.events.EventDispatcher;
7 import flash.utils.setTimeout;
8
9 // TestCase subclasses should always end with 'Test', the example
10 // doesn't because we don't want TestSuites in this directory.
11 public class TestCaseExample extends TestCase {
12 private var date:Date;
13 private var sprite:Sprite;
14
15 // TestCase constructors must be implemented as follows
16 // so that we can execute a single method on them from
17 // the TestRunner
18 public function TestCaseExample(testMethod:String = null) {
19 super(testMethod);
20 }
21
22 // This method will be called before every test method
23 override protected function setUp():void {
24 date = new Date();
25 // sprite = new Sprite();
26 // addChild(sprite);
27 }
28
29 // This method will be called after every test method
30 // but only if we're executing the entire TestCase,
31 // the tearDown method won't be called if we're
32 // calling start(MyTestCase, "someMethod");
33 override protected function tearDown():void {
34 // removeChild(sprite);
35 // sprite = null;
36 date = null;
37 }
38
39 // This is auto-created by the XULUI and ensures that
40 // our objects are actually created as we expect.
41 public function testInstantiated():void {
42 assertTrue("Date instantiated", date is Date);
43 // assertTrue("Sprite instantiated", sprite is Sprite);
44 }
45
46 // This is an example of a typical test method
47 public function testMonthGetterSetter():void {
48 date.month = 1;
49 assertEquals(1, date.month);
50 }
51
52 // This is an asynchronous test method
53 public function testAsyncFeature():void {
54 // create a new object that dispatches events...
55 var dispatcher:IEventDispatcher = new EventDispatcher();
56 // get a TestCase async event handler reference
57 // the 2nd arg is an optional timeout in ms. (default=1000ms )
58 var handler:Function = addAsync(changeHandler, 2000);
59 // subscribe to your event dispatcher using the returned handler
60 dispatcher.addEventListener(Event.CHANGE, handler);
61 // cause the event to be dispatched.
62 // either immediately:
63 //dispatcher.dispatchEvent(new Event(Event.CHANGE));
64 // or in the future < your assigned timeout
65 setTimeout( dispatcher.dispatchEvent, 200, new Event(Event.CHANGE));
66 }
67
68 protected function changeHandler(event:Event):void {
69 // perform assertions in your handler
70 assertEquals(Event.CHANGE, event.type);
71 }
72 }
73 }