dcsimg
Problems testing XML-RPC servers
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Giulio_Piancastelli
Posted On:   Monday, August 26, 2002 05:16 AM

I'm trying to use JUnit to test the interaction between an XML-RPC server and an XML-RPC client I have written. First thing, I'm setting up the client and the server in the setUp() method, then start the server. Finally, since I do not want the server to still be up and running after all the tests are completed, I'm trying to shutdown it in the tearDown() method. public class TestXmlRpc extends TestCase { private XmlRpcMyServer server; private XmlRpcMyClient client; public void setUp() { server = new XmlRpcMyServer(); client = new XmlRpcMyClient(); try { server.start(); } catch (Exception e) { e.printStackTrace(); } } // do some tests    More>>

I'm trying to use JUnit to test the interaction between an XML-RPC server and an XML-RPC client I have written. First thing, I'm setting up the client and the server in the setUp() method, then start the server. Finally, since I do not want the server to still be up and running after all the tests are completed, I'm trying to shutdown it in the tearDown() method.


			
public class TestXmlRpc extends TestCase {
private XmlRpcMyServer server;
private XmlRpcMyClient client;

public void setUp() {
server = new XmlRpcMyServer();
client = new XmlRpcMyClient();
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
}

// do some tests

public void tearDown() {
server.shutdown();
}
}

As I have undestand it, the JUnit framework calls setUp() and tearDown() for each test in the class. So, I end up building and starting an XmlRpcMyServer for as many times as the number of tests in the class, generating a random number of java.io.IOExceptions (Address in use: JVM_Bind) since the severs try to bind themselves to the same port.


An idea could be to start and shutdown a server in each method: not only I am not sure this would work, but also I do not understand why I can not use the same server for all the test requests.


Has anyone running in a similar problem, and/or can suggest a solution?


TIA,

Giulio Piancastelli.

   <<Less

Re: Problems testing XML-RPC servers

Posted By:   Anonymous  
Posted On:   Monday, August 26, 2002 11:29 PM

First, what you are doing doesn't read like unit testing to me, but rather like system testing. Perhaps you should think about how to make most of your tests independent on the communication between client and server (mockobjects might help).

Second, you can take a look at junit.extensions.TestSetup for setUp and tearDown methods that only get called once for a whole TestSuite. I think that the usage of this is a "test smell", though.

About | Sitemap | Contact