Mokin'

Solo disponible en BuenasTareas
  • Páginas : 4 (899 palabras )
  • Descarga(s) : 0
  • Publicado : 1 de febrero de 2011
Leer documento completo
Vista previa del texto
.

In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A computer programmer typically creates a mock object to test thebehavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.
Reasons for use
In a unit test, mockobjects can simulate the behavior of complex, real (non-mock) objects and are therefore useful when a real object is impractical or impossible to incorporate into a unit test. If an object has any ofthe 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 aredifficult 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).
For example, an alarm clock program which causes a bell to ring at a certain timemight get the current time from the outside world. To test this, the test must wait until the alarm time to know whether it has rung the bell correctly. If a mock object is used in place of the realobject, it can be programmed to provide the bell-ringing time (whether it is actually that time or not) so that the alarm clock program can be tested in isolation.
[edit] Technical details
Mockobjects have the same interface as the real objects they mimic, allowing a client object to remain unaware of whether it is using a real object or a mock object. Many available mock object frameworks allowthe programmer to specify which, and in what order, methods will be invoked on a mock object and what parameters will be passed to them, as well as what values will be returned. Thus, the behavior...
tracking img