Quantcast
Channel: Adobe Community : Popular Discussions - FlexUnit
Viewing all articles
Browse latest Browse all 25673

Async tests and Assert throws exceptions

$
0
0

Hi,

 

In a regular non-async test, something like Assert.assertEquals( "apples", "oranges" ); gives a nice report that the strings didn't match.  The test fails and the suite continues and all is good.  If the test is asynchronous, though, you get an uncaught exception, and a timeout on the test rather than a nice report.  Worse, it will cause a command-line based test to freeze with a stack trace showing (if you have a debug version of Flash, of course), until you hit the dismiss button.

 

Here's an example.  Without the Assert.assertEquals line, the test passes after two seconds as expected.  With the Assert.assertEquals in place, you get the behaviour I described.  So the question is, how do I use asserts in an asynchronous test?  I want the behaviour that you get with synchronous tests, i.e. a nice report and no pop-up dialog showing the stack.

 

        const TEST_COMPLETE:String = "testComplete";
        [Test(async)]
        public function myAsyncTest():void   
        {
            Async.proceedOnEvent( this, this, TEST_COMPLETE, 5000 );
            var t:Timer = new Timer(2000, 1);
            t.addEventListener(TimerEvent.TIMER, timeout);
            t.start();
        }
        private function timeout(e:Event):void
        {
            Assert.assertEquals( "apples", "oranges" );
            dispatchEvent( new Event(TEST_COMPLETE) );
        }

 

Any help?

Thanks!

DB


Viewing all articles
Browse latest Browse all 25673