views:

669

answers:

1

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?

+2  A: 

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. It's that what the TestRunner is supposed to do?

I'd start the registry in a setup and shut it down in a teardown method.

duffymo
I didn't write the main, the prior developer did. It's a manual "smoke test" that I am porting to junit
sal