Код: Выделить всё
fun getMockServerUrl(): String {
val server = MockWebServer()
server.dispatcher = object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
println("dispatch hit 🚀")
TODO()
}
}
server.start()
val url = server.url(path = "")
val api = Retrofit.Builder()
.baseUrl(url)
...
.create(MyApi::class.java)
Thread {
api.getData().enqueue(
object : Callback {
override fun onResponse(call: Call, response: Response) {
println("Response is ${response.body()}")
}
},
)
}.start()
return url.toString().also {
println("URL is $it")
}
}
- вызывается с правильным базовым URL-адресом localhost и может получить доступ к localhost из внешнего браузера. Это означает, что сервер запущен и работает
Код: Выделить всё
URL is $it - печатается, что вполне ожидаемо.
Код: Выделить всё
Response is null - Но попадание при отправке никогда не печатается. (Хотя он распечатывается при доступе из внешнего браузера): Это
Подробнее здесь: https://stackoverflow.com/questions/790 ... -triggered