0

I am writing instrumentation tests using Square's MockWebServer to mock server responses and OkHttpIdlingResource to wait for OkHttp to finish work until the remaining test steps continue. I am also using a MockWebServer dispatcher so that I can respond to certain requests differently depending on the path.

I am running into an issue where the tests work for some Android API versions and they don't work for others.

On Marshmallow the tests pass as expected. When I run on Android Pie, the MockWebServer responds to several requests, but then, for some reason, OkHttp throws a java.net.ConnectException.

If I hit my real web server everything works fine for any app version, it's only when using MockWebServer that I see this issue.

I have no idea what would cause this and the logs are not surfacing anything useful. In the failure case I can see that the MockWebServer has several successful 200 responses, but for some reason a ConnectException occurs during one of the calls.

The only weird thing I can see in the logs is that an Espresso ViewAssertion is logged before the last, failing, OkHttp request is logged. So it may be that the OkHttpIdlingResource is saying that it is idle when it really isn't.

Any ideas on what could be wrong?

neonDion
  • 2,278
  • 2
  • 20
  • 39
  • Please show your error log. – Robbit May 30 '19 at 03:31
  • 1
    So it turns out that my OkHttpIdlingResource was actually not waiting for all of my requests to complete and was running some verify code which then caused my test to fail and then my mock web server was torn down and that's why I was seeing the error. – neonDion May 30 '19 at 14:06
  • Does it have anything to do with Android Pie's not accepting 'http' calls anymore, only 'https' ? – bernardo.g Aug 28 '19 at 17:25

0 Answers0