Java and Object Orientation
Discusses tools, principles, and patterns relating to Java and Object Orientation.







Subscribe to "Java and Object Orientation" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.


Saturday, May 31, 2003
 

Eric Dobbs introduced me to easymock a couple of weeks ago. This java library lets you incorporate mock object testing into junits. I’ve been looking for a good place to try it out and settled on a JMS-based distributed caching system that I’m writing for my current employer.

The old way to junit the onMessage method of a MessageListener requires a running JMS server, an InitialContext, a connection, a session, and a call to session.createObjectMessage to create an ObjectMessage. You then set the payload on the ObjectMessage and invoke onMessage, passing in the ObjectMessage as the parameter.

But with easymock, you simply create a mockObjectMessage, specify the payload object to be returned when message.getObject is called, and then invoke onMessage, passing in the mockObjectMessage as the parameter. No JMS server, no initial context, no session, and no connection are required. The result of this approach is a unit test that requires much less infrastructure.


4:06:19 PM    


Click here to visit the Radio UserLand website. © Copyright 2003 Larry Sherrill.
Last update: 9/21/2003; 12:20:32 PM.
May 2003
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Mar   Jul