Wiki

Clone wiki

morefluent / Home

Story

The motivation for this project was to replace complex syntax in the exiting unit testing frameworks when dealing with asynchronous behaviors verification.

The goal was to have a fluent and self explanatory API that allows creating compact test code.

News

25/02/2011 - An as3signals extension of morefluent by Patric Mowrer is available on GitHub. Example test for signals:

package com.acme
{
    import flash.utils.setTimeout;
    
    import org.morefluent.integrations.flexunit4.signals.*;
    import org.flexunit.rules.IMethodRule;
    import org.morefluent.integrations.flexunit4.*;
    import org.osflash.signals.Signal;

    public class TestMorefluentSignalsFU4
    {
        [Rule]
        public var morefluentRule:IMethodRule = new MorefluentRule();
    
        [Test(async)]
        public function shouldPassOnSignal():void
        {
            // given
            var signal:Signal = new Signal();
            // when
            setTimeout(function():void { signal.dispatch(); }, 500);
            // then
            after(signal, 1000).pass();
        }
    }
}

12/07/2010 - Released 1.2RC1 with synchronous api for event verification.

// given
var dispatcher:EventDispatcher = new EventDispatcher();
observing("someEvent").on(dispatcher);
// when
dispatcher.dispatchEvent(new Event("someEvent"));
// then
assert(dispatcher).observed("someEvent", times(1));

How to use it?

To assert after event you do:

public function testShouldCatchAndPassOnEvent():void
{
    // given
    var timer:Timer = new Timer(100, 1);
    // when
    timer.start();
    // then
    after(TimerEvent.TIMER_COMPLETE).on(timer).assert(timer, "currentCount").equals(1);
}

If waiting for an event is not easy for any reason use polling:

//polling assertion with equals()
poll().assert(timer, "currentCount").equals(1);

//polling assertion with custom timeout
poll(2000).assert(timer, "currentCount").equals(1);

To use it with flexunit or flexunit4 take a look here

Help and support

Please join our mailing list

MoreFluent vs Fluint

Original Fluint test for checking timer timeout (using concrete function):

public function testTimerLongWay():void
{
    // given
    var timer = new Timer( 100, 1 ); 
    var asyncHandler:Function = asyncHandler( handleTimerComplete, 500, timer);
    timer.addEventListener(TimerEvent.TIMER_COMPLETE, asyncHandler, false, 0, true );
    // when
    timer.start();                  
}

protected function handleTimerComplete( event:TimerEvent, passThroughData:Object ):void 
{
    // then
    assertEquals(1, Timer(passThroughData).currentCount);   
}

Fluint using local function:

public function testTimerLongWay():void
{
    // given
    var timer = new Timer( 100, 1 ); 
    var asyncHandler:Function = asyncHandler(handleTimerComplete, 500, timer);
    timer.addEventListener(TimerEvent.TIMER_COMPLETE, asyncHandler, false, 0, true );
    // when
    timer.start();                  
    function handleTimerComplete( event:TimerEvent, passThroughData:Object ):void 
    {
        // then
        assertEquals(1, Timer(passThroughData).currentCount);   
    }    
}

MoreFluent version:

public function testShouldCatchAndPassOnEvent():void
{
    // given
    var timer:Timer = new Timer(100, 1);
    // when
    timer.start();
    // then
    after(TimerEvent.TIMER_COMPLETE).on(timer).assert(timer, "currentCount").equals(1);
}

If waiting for an event is not easy for any reason use polling:

//polling assertion with equals()
poll().assert(timer, "currentCount").equals(1);

//polling assertion with custom timeout
poll(2000).assert(timer, "currentCount").equals(1);

API

MoreFluentApi

Integrations

MoreFluentIntegration

Integration testing

IntegrationTesting

Authors

Morefluent has been coded and invented by Kris Karczmarczyk with a mental contribution from Szczepan Faber.

License

The MIT License

Copyright (c) 2009 Morefluent contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Updated