I often have to code against Twitter, and now against other Web Service APIs that I do not control.
I've tried to write test cases but it seems too difficult as:
For folks facing similar situations, I'd like to find out the solutions they've devised.
PS: I'm familiar with mock objects but I'd like to get more specific lessons learned -- for example I use a library to talk to Twitter (Twitter4J) which, when last I looked does not allow me to substitute a mock object for the Twitter Service.
Thanks.
In my projects (which rely on a variety of external web services) I've focused my testing on failure events. So when building a unit test for Facebook Connect I tried to pass junk data to my web service response processing methods to make sure that I could handle the service changing underneath me. Successful event testing wasn't something I put into a unit test because it creates so much cruft (like events in a timeline). A possible work around to this are to create a test account in your intended service and point your unit tests to that ID. If you make sure that your web service posting code doesn't include hard coded IDs (I like to create <Service>Config classes that are passed to <Service>Methods classes like FacebookMethods.auth(FacebookConfig config, String uid)) this lets me create a TestConfig for operations that will modify a service in a way that can't be undone or shouldn't be seen publicly).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With