【发布时间】:2019-03-12 13:29:42
【问题描述】:
我正在使用 Kotlin 协程,特别是使用 Retrofit 的 CoroutineCallAdapterFactory。然后我正在尝试对一个类进行单元测试,该类又使用 Retrofit 接口(下面的GalwayBusService)。
interface GalwayBusService {
@GET("/routes/{route_id}.json")
fun getStops(@Path("route_id") routeId: String) : Deferred<GetStopsResponse>
}
在我的单元测试中我有
val galwayBusService = mock()
然后尝试类似以下的方法来模拟调用该方法时返回的内容。问题在于 getStops 返回一个 Deferred 值。有什么特别的方法可以用来模拟这样的 API 吗?
`when`(galwayBusService.getBusStops()).thenReturn(busStopsResponse)
【问题讨论】:
标签: android kotlin mockito retrofit kotlinx.coroutines