1

I have written a unit test with MockWebServer to catch ConnectionExceptions thrown by Retrofit and convert them to a domain level error.

    @Test
fun `check that factory returns no internet error for ConnectException when no internet`() {
    val response = MockResponse()
        .setSocketPolicy(SocketPolicy.DISCONNECT_AFTER_REQUEST)

    whenever(connectionChecker.isConnected())
        .thenReturn(false)

    mockWebServer.enqueue(response)

    val result = apiService.getAllBreads()
        .subscribeOn(schedulerProvider.io())
        .observeOn(schedulerProvider.ui())
        .test()

    result.assertError(PawzNoInternetError::class.java)

}

This test works fine locally but it fails on Bitrise!

The code under test is a custom Retrofit CallAdapter.Factory, debugging the code locally, the thrown error is indeed a ConnectionException so the test passes. Running the test on Bitrise I get a :

java.io.IOException: unexpected end of stream on Connection

which causes the test to fail.

Does anyone know how I could fix this?

Stelian Morariu
  • 505
  • 7
  • 16

0 Answers0