Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 625
Tomas Brambora Avatar asked Nov 26 '25 00:11

Tomas Brambora


2 Answers

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.

like image 103
Aaron Digulla Avatar answered Nov 27 '25 13:11

Aaron Digulla


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.

like image 41
Michael Dillon Avatar answered Nov 27 '25 14:11

Michael Dillon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!