Best practicies for JUnit and RMI Apps, RMI Registry
Asked Answered
R

1

6

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?

Rowdyism answered 9/1, 2009 at 16:4 Comment(0)
P
5

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.

Psychic answered 9/1, 2009 at 16:20 Comment(1)
I didn't write the main, the prior developer did. It's a manual "smoke test" that I am porting to junitRowdyism

© 2022 - 2024 — McMap. All rights reserved.