Issue
I am trying to mock REST response for my Android App. Retrofit 2 and RxJava are used to implement network calls and these are new to me.
I was successfully able to mock using the tutorial here by using mockwebserver.
However, since it does not use Observable, mockwebserver does not register the call, I think.
My interface looks like this:
@POST("auth/token")
Observable<authenticationaccess> authenticate(
@Query("username") String username,
@Query("password") String password,
@Query("grant_type") String grantType,
@Query("scope") String scope);
And I call like this,
server.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody("{}"));
I found a few tutorials that use Dagger which required lots of coding for such a small thing. Is there any easier way to achieve this?
Solution
server = new MockWebServer();
server.start();
NetworkServiceHelper.init(String.valueOf(server.url("/")));
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_INTERNAL_ERROR));
Answered By - Prabin Timsina
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.