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?