I am developing an Android application using Retrofit 1.9.0 and trying to write some tests for it.
I have a separate HttpModule class which I created to decouple my other parts of Application from Retrofit's implementation specifics. So, all my calls are proxied via this HttpModule class.
HttpModule#login(LoginCredentials lc, HttpCallback<LoginResult> lr) will delegate to myRetrofitService.login(lc, new retrofit.Callback<SomeResponse>() {...}); and response from Retrofit's Callback objects will be wrapped into my own HttpCallback object and be invoked.
So I am trying to test this HttpModule here, possibly providing a "mock" http responses after checking valid request url and query.
Right now, I am creating a custom Client class for my RestAdapter to validate requests and generate my mock responses. It surely feels a lot of code and It would be lovely if I would get some help from other testing frameworks.
Also, I have to open up HttpModule to enable configuration from the outside world, such as setting the RestAdapter or Client, which I don't really fancy that much. I could supply two constructors (one accepting my test config), but since this HttpModule is currently implemented as an enum singleton, it would require some refactoring. Also I am not really fond of opening Retrofit-specific configuration to client code. Maybe I am being excessively ocd.
What do you guys think? Is there any testing framework that would ease this process? and what would be the most elegant/clear/concise/effective way to confine Retrofit-specific code to this HttpModule and at the same time provide means for testing (mocking) http responses?
Aucun commentaire:
Enregistrer un commentaire