views:

183

answers:

2

Hi there,

I am interested in your opinions on unittesting code that uses Corba to communicate with a server.

Would you mock the Corba objects? In Python that's sort of a pain in the ass because all the methods of Corba objects are loaded dynamically. So you're basically stuck with "mock anything".

Thanks!

Note: I believe I have not made myself clear enough, so I'll try to give a somewhat more concrete example:

A web application needs to display a page containing data received from the server. It obtains the data by calling server_pagetable.getData() and then formats the data, converts them to the correct python types (because Corba does not have e.g. a date type etc.) and finally creates the HTML code to be displayed.

And this is what I would like to test - the methods that receive the data and do all the transformations and finally create the HTML code.

I believe the most straightforward decision is to mock the Corba objects as they essentially comprise both the networking and db functionality (which ought not to be tested in unit tests).

It's just that this is quite a lot of "extra work" to do - mocking all the Corba objects (there is a User object, a server session object, the pagetable object, an admin object etc.). Maybe it's just because I'm stuck with Corba and therefore I have to reflect the object hierarchy dictated by the server with mocks. On the other hand, it could be that there is some cool elegant solution to testing code using Corba that just did not cross my mind.

+2  A: 

Don't try to unittest Corba. Assume that Corba works. Unittest your own code. This means:

  1. Create a unit test which checks that you correctly set up Corba and that you can invoke a single method and read a property. If that works, all other methods and properties will work, too.

  2. After that, test that all the exposed objects work correctly. You don't need Corba for this.

Aaron Digulla
Yes, but from time to time (in my case actually quite often), you just have to test some functionality that directly uses Corba. In my case, the server communicates with the client using Corba, so if I want to test that e.g. my object that wraps the Corba interface works fine, I have to include Corba in the test somehow.(Disclaimer: This is not my design, just something I've inherited and have to work with. :-) )
Tomas Brambora
Change the design in this respect. Also don't test the Corba compiler (unless you run into bugs and need to know how/whether something works). Make sure your code sets the right parameters. The next step would be to get the source for the server and test its code with unit tests. But avoid the round trips (as much as possible). Disclaimer: Reality beats paper.
Aaron Digulla
+1  A: 

I would set up a test server, and do live tests on that. Unittesting can be tricky with network stuff, so it's best to keep it as real as possible. Any mocking would be done on the test server, for instance if you need to communicate to three different servers, it could be set up with three different IP addresses to play the role of all three servers.

Michael Dillon