I'm looking to write a set of system integration tests for an RMI client application. I'd like to start the RMI server in JUnit 3.8.2 and then run those tests. Has anyone done this?
I'm using something like this in a pojo with main:
import java.rmi.registry.*; .... //setup try { java.rmi.registry.LocateRegistry.createRegistry(1099); System.out.println("RMI registry ready."); this.StartMyServer(); // client set up MyClient m = null; m = (MyClient) Naming.lookup("//MyHost/MyServer", m); // tests here } catch (MyClientException me) { System.out.println("MyClient fall down go boom"); } catch (MyServerException me) { System.out.println("MyServer fall down go boom"); } catch (Exception e) { System.out.println("Exception starting RMI registry:"); }
What's the best way to turn this into a junit test so the registry is started only once and the tests only run if the registry actually starts up? I could like to avoid having a test class with one test method with all the test code from main there, which is what I found myself doing before coming here.
Also, what should I watch out for when writing my tests? Any RMI testing gotchas?
RMI and CORBA(Common Object Request Broker Architecture) attempt to solve a problem that people thought was important in the early 1990s. However, today we can't consider RMI as modern technology and nowadays we have REST, SOAP as the de-facto standards for communicating with remote services.
A remote object registry is a bootstrap naming service that is used by RMI servers on the same host to bind remote objects to names. Clients on local and remote hosts can then look up remote objects and make remote method invocations.
The RMI registry is a simple server-side name server that allows remote clients to get a reference to a remote object. It typically is used to locate only the first remote object an RMI client needs to talk to. Then, that first object in turn, provides application-specific support getting references for other objects.
If you're using JDK 5 or higher, I'd recommend upgrading to JUnit 4.4. Annotations are a great help.
I'd also recommend reading this. I don't see why you'd write a separate main class to run tests. Isn't that what the TestRunner is supposed to do?
I'd start the registry in a setup and shut it down in a teardown method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With