• 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

JUnit testing RMI with Mocks...

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am trying to come up with the best way of unit testing an RMI server and client separately. I am thinking that the best way to test each part in isolation from the each other and network would be to use Mocks.

I am quite a beginner at Mock Objects so I was hoping anyone would have any suggestions on how to test an RMI client and server with Mocks to allow for code isolation.

Thanx for any help,

James.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you describe the interfaces of your RMI objects?
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Remote interface is quite simple, it has 4 methods that return int's and strings.

My Remote object is actually very simple, I start the Registry programmatically from another object and bind the Remote object to it. I use the UnicastRemoteObject as the base class of my Remote Object.

The client uses: Naming.lookup(lookupString);
to get the remote stub.

Is there a good way to unit test each in isolation and without the network with mocks?

Thanx for your help.

James.
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The biggest problem with RMI are the static methods in naming - you can't mock those directly. The solution is to not acces it directly, bur through an interface. The MockObjects library contains such an interface, inclusive a production and a mock implementation: http://mockobjects.sourceforge.net/javadoc/1.4/alt/java/rmi/Naming.html

BTW, "Unit Tests with Java" by Johannes Link contains a section on RMI.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic