title: MockWebServer - ConnectException: Failed to connect to
body: <p>When I start my test I get connect exception and I have no idea why.</p>
  
  <p>I found some code others authors and compare code and i didn't find anything wrong. I tried to change ports or remove it and it didn't help me.</p>
  
  <pre><code>@RunWith(AndroidJUnit4::class)
  class RideFragmentTest {
  
  @get:Rule
      val activityRule: ActivityTestRule&lt;MainActivity&gt; = ActivityTestRule(MainActivity::class.java)
      private val mockWebServer = MockWebServer()
      private val PORT = 8607
  
  @Before
      fun init() {
          mockWebServer.start(PORT)
          routeToFragment()
      }
  
  @After
      fun finish() {
          mockWebServer.shutdown()
      }
  
  @Test
      fun someTest() {
          val dispatcher = object : Dispatcher() {
              @Throws(InterruptedException::class)
              override fun dispatch(request: RecordedRequest): MockResponse {
                  when (request.path) {
                      "/something/current" -&gt; {
                          val jsonBody = asset(activityRule.activity, "something.json")
                          return MockResponse().setResponseCode(200).setBody(jsonBody)
                      }
                      "/something/save" -&gt; {
                          return MockResponse().setResponseCode(200)
                      }
                  }
                  return MockResponse().setResponseCode(404)
              }
          }
          mockWebServer.dispatcher = dispatcher
  
          assertDisplayed(..., ...)
      }
  }
  </code></pre>
  
  <pre><code>D/OkHttp: --&gt; GET http://127.0.0.1:8607/something/current
  D/OkHttp: --&gt; END GET
  HTTP FAILED: java.net.ConnectException: Failed to connect to /127.0.0.1:8607
  </code></pre>
  
  <p>I didn't find any strange logs.</p>