Skip to main content
September 3, 2009
Resuelto

Run a test suite (scenario) on a RemoteObject

  • September 3, 2009
  • 4 respuestas
  • 1981 visualizaciones

Hi,

I'm trying to run a test suite on a remote object.

It works fine, but i want to do a "scenario" with async request.

Here is my source :

        [Test(async)]
        public function ping():void
        {
            //_proxyTest.addEventListener(FaultEvent.FAULT, Async.asyncHandler(this, onNotWantFaultEvent, SHORT_TIME, null, onWantTimeOut), false, 0, true);
            Async.failOnEvent(this, _proxyTest, FaultEvent.FAULT);
            _proxyTest.addEventListener(ResultEvent.RESULT, Async.asyncHandler(this, onWantResultEvent, SHORT_TIME, null, onNotWantTimeOut), false, 0, true);
            _proxyTest.ping();
        }
       
        [Test(async)]
        public function pingTimeOut():void
        {
            Async.failOnEvent(this, _proxyTest, ResultEvent.RESULT);
            _proxyTest.addEventListener(FaultEvent.FAULT, Async.asyncHandler(this, onWantFaultEvent, SHORT_TIME, null, onWantTimeOut), false, 0, true);
            _proxyTest.pingTimeOut();
        }
       
        /*
            Handlers
        */
       
        // ResultEvent and FaultEvent
       
        protected function onWantResultEvent( event:ResultEvent, passThroughData:Object ):void
        {
        }
       
        protected function onNotWantResultEvent( event:ResultEvent, passThroughData:Object ):void
        {
            Assert.fail("Request return result");
        }
       
        protected function onWantFaultEvent( event:FaultEvent, passThroughData:Object ):void
        {
           
        }
       
        protected function onNotWantFaultEvent( e:FaultEvent, passThroughData:Object ):void
        {
            Assert.fail("Request fault : " + e.message );
        }
       
        // Timeout
       
        protected function onWantTimeOut( passThroughData:Object ):void
        {
        }
       
        protected function onNotWantTimeOut( passThroughData:Object ):void
        {
            Assert.fail('Request timeout');
        }

My idea is to execute the pingTimeOut test after the end of ping Test. Because i am listening same event on the two tests (result event).

Could you propose a solution ?

Thanks

Mikael

Este tema ha sido cerrado para respuestas.
Mejor respuesta de mlabriola

The only suggestion off the top of my head is to be sure you are running the Beta 2 code. There was a bug in Beta 1 around the naming of 'expects' versus 'expected'. In Beta 2 they both of these words work to set an expected error.

Mike

4 respuestas

Participating Frequently
September 3, 2009

Mikael,


You can ensure that pingTimeOut is run after ping() by using the order metadata. So:

        [Test(async,order=1)]
        public function ping():void {

          ...
        }
      
        [Test(async,order=2)]
        public function pingTimeOut():void {
        }


However, to me it looks like you are trying to test a couple of things in each test here.

In the first test, your code currently reads that it wants to see a result and you want it to fail if you received either a fault OR a timeout.

In the second test, you want to see a timeout or a fault and fail if you see a result event.


Here is another way to look at this, just some thoughts to consider. (p.s. I didn't compile this code, just typed it in but I think it should be close)

package sometests {
    import mx.rpc.AsyncToken;
   
    import org.flexunit.Assert;
    import org.flexunit.async.Async;
    import org.flexunit.async.TestResponder;

    public class ROTest {
        [Test(order=1)]
        public function testPing():void {
            var responder:IResponder = Async.asyncResponder( this, new TestResponder( handleResult, handleFault ), 100, null, onTimeOut );
            var token:AsyncToken = _proxyTest.ping();
            token.addResponder( responder );
        }

        [Test(order=2,expects="flexunit.framework.AssertionFailedError")]
        public function testPingTimeOut():void {
            var responder:IResponder = Async.asyncResponder( this, new TestResponder( handleResult, handleFault ), 100, null, onTimeOut );
            var token:AsyncToken = _proxyTest.pingTimeOut();
            token.addResponder( responder );
        }

        protected function handleResult( data:Object, passThroughData:Object ):void {
           
        }

        protected function handleFault( info:Object, passThroughData:Object ):void {
            Assert.fail("Request fault : " + e.message );     
        }

        protected function onTimeOut( passThroughData:Object ):void {
            Assert.fail("Timeout!!" );
        }       
    }
}

mike

September 3, 2009

Thanks for your help but the second test always don't work ...

The function :

protected function onTimeOut( passThroughData:Object ):void
        {
            Assert.fail('Request timeout');
        }

Is correctly called, but flexunit, indicate that test is bad (ignore metadata : expects="flexunit.framework.AssertionFailedError" )

Have you an idea on the problem ?

mlabriolaRespuesta
Participating Frequently
September 3, 2009

The only suggestion off the top of my head is to be sure you are running the Beta 2 code. There was a bug in Beta 1 around the naming of 'expects' versus 'expected'. In Beta 2 they both of these words work to set an expected error.

Mike