Tuesday, December 1, 2009

Using Mock Objects in a Flex Application

The usage of mock objects in a Flex application may represent a very powerful way to improve development speed and increase the quality of the tests you will prepare. A mock object can simulate the  behavior of complex, real (non-mock) objects and are therefore useful when a real object is not yet available (server side development is late!) or when a real object is impractical or impossible to incorporate into a unit test, the Mocker class we¹ll discuss during this session is an easy way to create tons of mock objects with few line of codes and with a predictable behavior. 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)
Learn how to generate mock objects with the open source solution inspired by mockito! 

No comments: