0

Do not get a callback from Retrofit when testing (under JVM).

Testing App with Robolectric (3.0), Wiremock (1.57:standalone) and Mockito (1.10.19).

The App uses Retrofit (1.9) to connect with a back-end API. App has services that call the API via Retrofit, and the activities are bound to the services.

Debugging and logs of the test run show that the activity calls the service, service calls retrofit, and retrofit returns result from Wiremock (as expected).

I/com.levld.client.rest.RestAdapterFactory: <--- END HTTP (6208-byte body) W/com.levld.client.rest.RetrofitErrorHandler: Internal server error

The internal server error is on purpose to trigger the Retrofit errorhandler (status code set by Wiremock).

When debugging the errorhandler the processing stops when Retrofit tries to callback the service. Variables in the debugger show that the callback is set to the calling service.

Your help and suggestions are very much appreciated!

nordic70
  • 130
  • 2
  • 9

1 Answers1

0

Resolved by setting synchronous executor for Retrofit. This triggers synchronous execution of the api calls, but still returns the results as callbacks to the calling services. Asynchronous functional code in the services layer is unchanged!

Synchronous executor code: https://stackoverflow.com/a/27341424/4413233.

p.s. Robolectric is actually intended for unit testing

Community
  • 1
  • 1
nordic70
  • 130
  • 2
  • 9