Mock object

Mock objects (from English to mock, pretend something ') are in software development objects that are used as placeholders for real objects within the module tests.

It is not always possible or desirable to test completely isolated a single object. If the interaction of an object with its environment are reviewed, the environment must be simulated before the actual test. This can be cumbersome, time consuming, or even only limited or not possible.

In these cases, mock objects can help. Mock objects implement interfaces accesses over which the object to be tested on its surroundings. They make sure that the expected method calls complete, with the correct parameters and are carried out in the expected order. The mock object does not return any real data, but before the test case suitable fixed values ​​. The mock object can thus be used to recreate a certain behavior.

Use

Specifically, mock objects are useful if the "real" object

  • Nondeterministic results (for example, the current time or the current temperature );
  • Difficulties in the preparation or during the execution of preparing (eg when testing user interfaces );
  • To show behavior that is difficult to trigger (eg a network error );
  • Slow or very complex (eg a complete database that needs to be initialized before each test only );
  • Does not yet exist (eg in larger software or hardware development projects);
  • Information and methods exclusively for testing purposes (and not for its actual task ) would provide.

Unlike unit testing integration testing test the entire system of interconnected components (English units). This normally no mock objects are used.

577233
de