Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

This page assumes that you are already familiar with writing basic test cases and asynchronous testing, as well as familiarity with [Before] and [After] methods. Please follow the links provided if you do not feel comfortable with these concepts.

...

In order to take advantage of the UIImpersonator, two metadata attributes need to be added: async] and ui. The async attribute lets FlexUnit know that the method in question is asynchronous, that is, that we cannot assume the method is done with everything simply because the method itself has completed execution. Waiting on a FlexEvent.CREATION_COMPLETE, or Event.ADDED for pure AS3, will be the most common use-case of asynchronous behavior when dealing with UIImpersonator. The ui attribute lets FlexUnit know that you will be interacting with the display list and is necessary for implementing UIImpersonator.
:-Note: While async is not ''necessarily'' required to implement UIImpersonator, in ''most'' cases, if you need something to be on the display list, you also need asynchronous testing.

...

  • It is easier to write the test this way. If we were to do the adding/removing in the test case itself, we would need to add various asynchronous event listeners and event need to move the success criteria ''out of'' the test case itself and ''into'' an event listener instead. For more on this, compare the two walk-throughs Writing an Asynchronous Test vs. Using Asynchronous Startup.
  • It is easier to read. We have just effectively created a test that '''only contains functionality that we are testing'''. Since we are ''presupposing'' adding and removing the custom button to the display list works and not actually ''testing'' it, the test very clearly shows what is being tested without adding code that isn't being tested.unmigrated-wiki-markup
  • It is easier to reuse. By using \ [Before\] and \ [After\] methods, now we have a [[Tests and Test Cases|test case]] ready to test ''any'' functionality on the {{MyButton}} class that needs it to be added to the display list. For example, we may want this test case to test setting the custom style, or test expected behavior if the style is undefined, etc. All we would have to do is add the additional tests without having to worry about re-using the {{UIImpersonator}}, since the {{[Before]}}/{{[After]}} will do this automatically.

Wiki MarkupIn other words, although you don't ''have to'' use \ [Before\] and \ [After\], it is generally a good practice.

Why Use UIImpersonator? - Part 2

...