1

In my project, I have implemented networking calls using java.net.HttpUrlConnection.

Now, I want to test the responses I get from the real server for these http requests. I'm using robolectric framework in combination with powermock.
When running the test, some of the responses say particular headers are missing (E.g., 'Invalid or missing the origin header'), although I have put all necessary headers as request properties. The responses are all okay while running on real device, and also while testing on Postman with the same headers.

Now, as far as my understanding, robolectric has an intermediate HTTP layer which intercepts the request calls. I have tried

FakeHttp.getFakeHttpLayer().interceptHttpRequests(false);

But this still results in same error.

What is the reason of such unexpected erroneous response and what is the walk-around through this, i.e. how to test the response from real server using robolectric framework?

Thank you.

Deb Sourav
  • 51
  • 3
  • _"how to test the response from real server using robolectric and powermock?"_ I don't understand how powermock is relevant in this context..? You're not mocking the HTTP requests. Also you might be interested in [this](https://stackoverflow.com/a/21982695/2410641). – ashu Dec 04 '20 at 11:36
  • Powermock is not directly relevant in this context. I mentioned it because I'm currently using the combination of Robolectric and Powermock to setup my test environment. Anyway, I have edited the title for clarification.. – Deb Sourav Dec 04 '20 at 11:48
  • I read the comment in the link you mentioned. But it's not clear whether I can test the Real server responses or not if I use HttpUrlConnection (I don't want to mock server responses). @ashu – Deb Sourav Dec 04 '20 at 11:51

0 Answers0