• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Uses of Mock Objects

 
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are mock objects just that - mock - and would they never become real objects.
Can you give us an explaination of mock objects, please.
What are the geographical hotspots of XP currently?
Obviously Brazil is one of them.
It doesn't seem to have taken Europe by storm.
Yet.
regards
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before using Business delegate pattern my friends used mock objects to simuate the return objects from EJB tier. Are you talking anout theos objects?
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mock objects are just fake objects that implement a required interface (or possibly a sub-class of a real class).
They usually do nothing, and return nothing when called.
For example, in JDBC, I could make a MockResultSet that implemented every required method, but just returned null (or 0 or false).
Now when unit testing, or in early development, I can use that MockResultSet object any place where my class needed a ResultSet. This will enable me to unit test without having to connect to a database. Of course, the mock object will not actually return any data. But I can fix that by enhancing my MockResultSet object to always return the same kind of data.
There is an open source effort at MockObjects which is a set of mock objects specifically developed for unit testing with JUnit. They have such things as a MockResultSet, MockHttpServletRequest, MockMessage (for JMS), and many more. People use these mock objects to test EJBs. Instead of testing your EJB client in the container, use a MockContext which returns a local implementation of the bean's interface. (Very similar to what Pradeep was talking about)
[ September 11, 2003: Message edited by: Michael Zalewski ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pradeep and Michael.
I think my main concern is whether mock objects are retained or as their use is as transient as UML models and you would expect proper objects after each iteration.
regards
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many mocks are for test only. One neat mock trick is sometimes called "self shunt" where a JUnit tester also implements interfaces to impersonate part of the system. Say I have a reader that reads a stream one line at a time and calls a transformer to handle each line. How to I test the reader if I haven't writen the transformer yet? I impersonate the transformer!

This gets tricky in a hurry. I've only bothered to make it work a couple times. Any other examples to help us all along?
 
Author
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by HS Thomas:
Are mock objects just that - mock - and would they never become real objects.
Can you give us an explaination of mock objects, please.
What are the geographical hotspots of XP currently?
Obviously Brazil is one of them.
It doesn't seem to have taken Europe by storm.
Yet.
regards


A MockObject is a test stub. You use it to stub up a database or a UI, or something else that the module under test depends upon.
 
reply
    Bookmark Topic Watch Topic
  • New Topic