haysclark / mockito-flex

2 stars 0 forks source link

mockito-flex

Logo

News

18/11/2014 - Version 1.4M7 available via maven repository. Please use sample project as a reference. Also check [wiki](Maven Setup) for the details.

30/09/2010 - Latest milestone 1.4.M4 has decreased size - no longer linking with unit testing libraries. Also fixes calling arguments as functions for stubs.

27/08/2010 - New 1.4 milestone available - provides two enhancements:

// stubbing function call of a function
function someService(token:AsyncToken, resultFunction:Function, failureFunction:Function):void {...}

given(service.someService(any(), any(), any()))
              .will(useArgument(1).asFunctionAndCall(new ResultObject()));

// stubbing function call of a function
function someService(token:AsyncToken, responder:IResponder):void {...}

given(service.someService(any(), any()))
              .will(useArgument(1).method("result").callWithArgs(new ResultEvent(...)));

10/08/2010 - New 1.4 milestone available - flexunit 4 updated to 4.1-beta3.26

10/08/2010 - RC5 made a final 1.3 release.

24/06/2010 - Released RC5 of Mockito 1.3. It allows using FlexUnit4 rules instead of the runner for the mock preparation and assignment.

03/03/2010 - Released RC3 of Mockito 1.3. Recompiled and updated to the latest flexunit4.

03/02/2010 - Released RC2 of Mockito 1.3. It allows adding [Mock] metadata on the class level and smart type guessing from a field when autocreating mocks. More details here.

02/02/2010 - Released RC1 of Mockito 1.3. It comes with flex unit 4 integration and more.

A sample test with FlexUnit4:

import com.acme.TestClass;
import org.mockito.integrations.verify;

[RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
public class MockingWithFlexUnit4
{
    [Mock(type="com.acme.TestClass")]
    public var mockie:TestClass;

    public function MockingWithFlexUnit4()
    {
    }

    [Test]
    public function shouldVerifyMockInvocation():void
    {
        // when
        mockie.argumentless();
        // then
        verify().that(mockie.argumentless());
    }
}

For more details please refer release notes.

01/10/2009 - A new milestone available for download. It adds ordered verification.

30/08/2009 - A good starter by Shanon click here. Thanks for writing it!

12/08/2009 - Mockito 1.1 released. Please read release notes.

02/08/2009 - Release Candidate 1 is out. Feedback is welcome. Read [release notes.(releases/Release1.1)

31/07/2009 - Integration test case for asunit is out there! Thanks James!

23/07/2009 - Mockito 1.01 released. Read release notes.

09/07/2009 - Added wiki with basic tutorial

08/07/2009 - Added some asdocs and basic tutorial. Check out the sources.

08/07/2009 - Started official mockito mailing list.

07/07/2009 - InfoQ mentions mockito-flex in it's article.

24/06/2009 - Mockito 1.0 released. Read release notes.

Milestones

M1.2.3 - Adds ordered verification:

inOrder().verify().that(someone.firstFunction());
inOrder().verify().that(someone.secondFunction());

Please note that you should not pass additional verifiers like times(n) to a verify function. If you do this the behavior is not well defined. I may need to change the API a little bit but for now just please don't use it.

M1.2.2 - Upgraded asmock to version 0.9

M1.2.1 - Adds support for calling original function for stubs:

given(someone.something(any())).will(callOriginal());

Story

Mockito for Flex has been created during the Hack Day session in //Sabre Airline Solutions// in just two days. The main idea was to introduce a better and simpler testing for Flex to use with the //Sabre CSS project//. We made hacks on asmock framework and gave it a new face.

More details on motivations behind mockito can be found on Mockito for java site.

Many thanks go to David Endicott for letting us publish the results of the Hack Day under open source.

We would like to thank also Richard Szalay, Asmock author, for his excellent work.

How to drink it?

Please download the latest version from the download section, put the libraries in your lib folder.

If you are using flex unit for your unit tests, you can extend a MockitoTestCase and start writing your tests. For other unit testing frameworks please check the integrations wiki.

After that you can start verifying interactions:

package com.acme
{
    import mx.collections.ArrayCollection;

    import org.mockito.MockitoTestCase;

    public class TestArray extends MockitoTestCase
    {
        public function TestArray()
        {
            // you need to specify classes to mock here
            super([Array, ArrayCollection]);
        }

        public function testShouldDemoVerificationAPI():void
        {
            // mock creation
            var array:Array = mock(Array) as Array;
            // using mock object - let's pretend the following two lines are part of our SUT 
            array.push("1");
            array.pop();
            // unlike a record-playback frameworks, mockito doesn't throw any "unexpected interaction" exception

            // selective & explicit verification
            // later you can verify ONLY what you are interested in
            verify().that(array.push("1"));
            verify().that(array.pop());
        }

        public function testShouldDemoStubbingAPI():void
        {
            var list:ArrayCollection = ArrayCollection(mock(ArrayCollection, "collection", [[]]));
            // stubbing - before execution
            given(list.getItemAt(1)).willReturn("A");

            // let's pretend the following is executed within SUT:
            // this call returns 'A' because it was stubbed
            assertEquals("A", list.getItemAt(1));

            // this call returns null because list.getItemAt(2) was not stubbed
            assertNull(list.getItemAt(2));
        }
    }
}

Documentation and examples

To get familiar with the framework please take a look at the tutorial. There is asdoc available as well in the downloads section.

Also please check the additions and contributions that are not part of the framework yet but you may find them interesting.

Integrations with different unit testing frameworks are described here.

A good starter also can be found here

If you want to use maven please refer to [[Maven Setup|Maven Setup]].

Releases

Release history

Who is the bartender?

This time flex mockito flavour is served to you by Kris Karczmarczyk and Szczepan Faber. But credits also go to all other contibutors of the mockito for java as we used and tried some of the new concepts.

How much is it?

License