FlexUnit4 Async Testing Events

When doing Unit testing in FlexUnit 4, you can test Async event firing. This is a tricky test if there are multiple events being fired. The reason it gets tricky is because of the single threaded nature of Flex.

When you simply dispatch one event ofter the other, they are added to the display stack and thus handled in REVERSE order when removed from the stack. However, if you are using remote calls, the stack is given a change to execute, while the remote call is sent off and thus Async events happen in NORMAL order. What makes this really tricky is if you have a combination of local events (reverse order) and remote events (normal order)

Here are some high level examples:

Example 1

dispatchEvent(Event1)

dispatchEvent(Event2)

dispatchEvent(Event3)

Correct Async testing is now done in reverse order, since each event is added to the display stack

Async.proceedOnEvent(this, someEventDispatcher, Event3, checkVars3, 500, null, noEventFired);

Async.proceedOnEvent(this, someEventDispatcher, Event2, checkVars2, 500, null, noEventFired);

Async.proceedOnEvent(this, someEventDispatcher, Event1, checkVars1, 500, null, noEventFired);

Notice the order of the Async.proceedOnEvent is reversed

Example 2

remote call(Event1)

dispatchEvent(Event2)

dispatchEvent(Event3)

Async.proceedOnEvent(this, someEventDispatcher, Event1, checkVars1, 500, null, noEventFired);

Async.proceedOnEvent(this, someEventDispatcher, Event3, checkVars3, 500, null, noEventFired);

Async.proceedOnEvent(this, someEventDispatcher, Event2, checkVars2, 500, null, noEventFired);

Notice the remote call clears properly, but the local calls are reverse order.

So the only way to do this is to understand that if a remote call is executed, you check for it and that if there are any local events, they are placed on a stack until no more events or a remote event takes place and then checked in reverse order.

Tricky….

Advertisements

FlexUnit Assert Message Meanings

ASSERTION METHOD MEANINGS
assertEquals Asserts that two values are equal.
assertContained Asserts that the first string is contained in the second one.
assertNotContained Asserts that the first string is not contained in the second one.
assertFalse Asserts that a condition is false.
assertTrue Asserts that a condition is true.
assertMatch Asserts that a string matches a regular expression (regexp).
assertNoMatch Asserts that a string doesn’t match a regexp.
assertNull Asserts that an object is null.
assertNotNull Asserts that an object is not null.
assertNotUndefined Asserts that an object is defined.
assertUndefined Asserts that an object is undefined.
assertStrictlyEquals Asserts that two objects are strictly identical.
assertObjectEquals Asserts that two objects are equal.
  • Calendar

    • November 2017
      M T W T F S S
      « Dec    
       12345
      6789101112
      13141516171819
      20212223242526
      27282930  
  • Search