Kotlin unit test Exception when mocking suspend function java.io.EOFException: Premature end of stream: expected 1 bytes

It turned out that the function readText() hasn't been mocked properly. It is an extension function on HttpResponse and it has to be mocked using mockkStatic function, for example like this:

@BeforeEach
fun setup() {
    mockkStatic(HttpResponse::readText)
}

setup() will be executed before each @Test, because it is marked with @BeforeEach annotation.