Flex Mock Testing Frameworks: Comparative Analysis

Post on 10-May-2015

2.114 views 0 download

Tags:

description

The presentation gives a comparative analysis of various mocking frameworks available to help writing unit tests in Actionscript/Flex

Transcript of Flex Mock Testing Frameworks: Comparative Analysis

Mocking in ActionScript 3.0: Comparative Analysis of various

mocking frameworks

Basic HighlightsImportance of Mocking in Unit TestingHow to Mock?Exploring various mocking frameworksHands On some frameworksQ & A

What is Mocking?

What is Mock Object?

mock objects are simulated objects that mimic the

behavior of complex, real objects in controlled ways

Why to Mock?

When to Mock?

Mock == Actual Object?

If an object has any of the following characteristics, it may be useful to use a mock object in its place:

- supplies non-deterministic results (e.g. the current time or the current temperature);- has states that are difficult to create or reproduce (e.g. a network error);- is slow (e.g. a complete database, which would have to be initialized before the test);- does not yet exist or may change behavior;- would have to include information and methods exclusively for testing purposes (and not for its actual task).

How to mock?

Example:

The Greeting component says Hello in any language.Greeting uses a Translator component to translate “Hello” from English to the selected language.

ITranslator is an interface containing the translate method – parameters from, to and word, which returns the translated word;

Traditional Way

Vs

Mocking Frameworks

Traditional Way

Evolution of Mocking Frameworks

Mock4AS

MockAS3

Mockolate

Mock4ASRecord, Expect & VerifyAdded Mock into Traditional ApproachMore of Traditional touch and posses similar

issuesLess mature

MockAS3Expectation BasedSimilar to Mock4AS in approachEnhanced Setting Expectations

* Receive Count , Property, Ordering Expectations, Calling Functions

Posses problems similar as in Traditional approach

FlexUnit:Runners & Rules

Runners are classes that implement IRunner, and have the capability to run specific types of

suites, tests, or methods.Rules are an advanced concept whose basic functionality is similar to

the [Before] and [After] concepts, allowing for reusable, dynamic classes that will execute

functionality before and after each test.

Kick started the concept of proxy mock objects

Purely Record-Replay BasedTotally bypassed the Traditional ApproachDifficult & complex to implementEnhanced & Advance Features:

Mock RepositoryMulti-Platform support (Flexunit, Asunit, Fluint..)Argument ConstraintsStub | Dynamic | Strict MocksEvent Stubbing …

Purely Expectation BasedBased on Mockito for JavaEasy to learn & integrateMatcher, Hamcrest API integratedEmploys the concept of Rule & Runner in

FlexunitNot much advanced & mature features like

ASMock

MockolateInclude Good aspects of ASMock & Mockito Expectation & Record-Replay basedNice | Strict | Partial MocksMocking & StubbingTest SpiesDecorators like EventDispatcher, HttpServiceCannot mock classes in default package

What Suites You??

Questions??