6.15 Summary


6.15 Summary

A dummy object is an object that replaces another object for the duration of a test. It implements the same interface as the "real" object, but replaces complex calculations with constant returns, throws exceptions when ordered to do so, and does some additional parameter validation or other things needed only in the test. Mock objects are special dummy objects that additionally handle the specification of the expected behavior and the validation of the actual behavior.

The main argument in favor of using dummies is independence in the tests and related design improvements. There are many more benefits and drawbacks such that mock objects should not be used reflexively but solely by carefully weighing the positive and negative implications against each other. Typical applications include access to files or other external resources and integration of external components. Dummy objects and mocks will also play an important role later on in Chapter 9, Persistent Objects, and Chapter 12, Web Applications.




Unit Testing in Java. How Tests Drive the Code
Unit Testing in Java: How Tests Drive the Code (The Morgan Kaufmann Series in Software Engineering and Programming)
ISBN: 1558608680
EAN: 2147483647
Year: 2003
Pages: 144
Authors: Johannes Link

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net