Virtual mock

From Wikipedia, the free encyclopedia

Virtual Mocks are a way to mimic the behavior of real objects in a controlled way. A computer programmer typically creates virtual mocks to test the behavior of some other object just like mock objects, although Virtual Mocks can be used to mock concrete classes.

Contents

[edit] Reasons for use

The reasons are the same reasons as mock objects. The only difference is the scope. While mock objects can only mock interface, virtual mocks can mock any classes (real objects)

[edit] Technical details

Virtual Mocks use aspect-oriented programming techniques to intercept the regular flow of the code, allowing a client object to remain unaware of whether it is using a real object or a mock object. Available virtual mock frameworks allow the programmer to specify which 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 of a complex object such as a network socket can be mimicked by a mock object, allowing the programmer to discover whether the object being tested responds appropriately to the wide variety of states such objects may be in.

[edit] Use in test-driven development

Although one of the benefits of test-driven development is the creation of loosely coupled code, there is a growing voice that too many interfaces makes the code complex and hard to understand. While Virtual Mocks allows to mock interfaces it allows the programmer to choose not to de-couple the code, and mock classes (real objects). This minimizes the need to design for testing.

[edit] See also

mock object

[edit] External links