OkHttp MockWebServer fails to accept connections when restarted

前端 未结 2 1767
情深已故
情深已故 2021-02-20 17:00

I\'m using the OkHttp MockWebServer to mock my server responses for unit tests.

It works great for the first test, but on the 2nd test my client fails with:

相关标签:
2条回答
  • 2021-02-20 17:39

    Your second request is using the URL of the first MockWebServer instance. (Each instance has a distinct URL.)

    0 讨论(0)
  • 2021-02-20 17:43

    This localhost connection fails because it does not belong tot he mock server. Use this instead (mockHelper.getHost()).willReturn(okhttpMockWebServer.url("/").toString())

    0 讨论(0)
提交回复
热议问题