pythonunit-testingmockingcorba

Unittesting Corba in Python


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

Would you mock the Corba objects?

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.


Solution

  • 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.