Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Monk objects
1. Mock Objects
Replace with
a graphic
Kishan M V White Master
5.5” Tall & 4.3” Wide
Radhakrishna Bhat
08/28/2009
Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 1
2. Mock Objects
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 the behavior of some
other object Also good for bringing slides over from white template
In a unit test, mock objects can simulate the behavior of complex, real
(non-mock) objects and are therefore useful when a real object is
improper.
Mock objects 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 allow
the programmer to specify which, and in what order, methods will be
invoked on a mock object and what parameters will be passed to
themactical or impossible to incorporate into a unit test
®
Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 2
3. Technical details
Mock objects have the same interface as the real objects they
mimic.
This allows a client object to remain unaware of whether it is
using a real object or a mock object.
Many available mock object frameworks allow the programmer
to specify which, and in what order, methods, parameters 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.
®
Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 3
4. Frameworks
A Mock Object Framework is a set of programmable APIs that allow
creating Mock and Stub Objects in an easier fashion. Mock
Frameworks save the developer from the need to write repetitive code
to test or simulate object interactions.
Some of Java Mock Object frameworks
Jmock
Easymock
Mockmaker
®
Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 4
5. Limitations
Refactorings code can break the tests easily
Results in increased maintenance to keep tests current
Sometimes too much decoupling rather than straightforward unit tests
with JUnit
®
Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 5
6. Better by Adobe
Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6