Jump to content

Virtual mock: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
→‎External links: remove now-blacklisted typemock.com link
Elilo (talk | contribs)
Line 17: Line 17:
[[Mock object]]
[[Mock object]]


* [http://www.typemock.org Typemock]
* [http://code.google.com/p/moq/ Moq]
* [http://code.google.com/p/moq/ Moq]



Revision as of 16:17, 15 January 2009

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.

Reasons for use

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

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.

Use in test-driven development

Although one benefit of test-driven development is the creation of loosely coupled code, too many interfaces can make the code complex and hard to understand. In addition to enabling the mocking of interfaces, Virtual Mock also allows the programmer not to decouple the code and mock classes (real objects). This minimizes the need to design for testing.

See also

Mock object