android - 如何在android中使用mockito编写单元测试进行改造
问题描述
我有一个简单的演示者,我想为其编写一个 Mockito 单元测试。
这是演示者类的代码,我在其中调用 api 并获取响应并通过使用接口向活动类(视图)发送响应:
class TrendingGifsPresenter(private val iTrendingGif: ITrendingGif, private val iShowError: IShowError) {
fun getTrendingGifs(offSet: Int) {
val trendingGifs: Call<TrendingGifsModel> = ServiceRegistry.getInstance().getApi().getTrendingGifs("Z23s0syKe5njqYEIt8WjarxhNy9aZFaZ", offSet)
trendingGifs.enqueue(object : Callback<TrendingGifsModel> {
override fun onFailure(call: Call<TrendingGifsModel>?, t: Throwable?) {
println(t!!.localizedMessage)
iShowError.showError()
}
override fun onResponse(call: Call<TrendingGifsModel>?, response: Response<TrendingGifsModel>?) {
if (response != null && response.isSuccessful && response.body() != null && response.body()!!.meta!!.status==200) {
iTrendingGif.setTrendingGifs(response.body())
}
}
})
}
fun getLoadMoreTrendingGifs(offSet: Int) {
val trendingGifs: Call<TrendingGifsModel> = ServiceRegistry.getInstance().getApi().getTrendingGifs("Z23s0syKe5njqYEIt8WjarxhNy9aZFaZ", offSet)
trendingGifs.enqueue(object : Callback<TrendingGifsModel> {
override fun onFailure(call: Call<TrendingGifsModel>?, t: Throwable?) {
println(t!!.localizedMessage)
iShowError.showError()
}
override fun onResponse(call: Call<TrendingGifsModel>?, response: Response<TrendingGifsModel>?) {
if (response != null && response.isSuccessful && response.body() != null && response.body()!!.meta!!.status == 200) {
iTrendingGif.loadMoreTrendingGifs(response.body())
}
}
})
}}
解决方案
推荐阅读
- python-3.x - AWS vs localhost 上的可变 time.sleep(X.XX) FPS 结果
- algorithm - 在熟人列表中找到名字的复杂性是什么
- php - 在 public_html 之外存储图像
- node.js - 是否可以使用 google-spreadsheet-to-json 并部署为 firebase 功能?
- php - php mysql准备好的语句LIKE在Wordpress中不起作用
- python - 如何合并元组列表
- javascript - 使用 mocha-allure-reporter 和 Cypress 的 Allure 报告中不显示步骤
- c# - 更改第三方引用的 dll 属性(产品名称)
- javascript - JavaScript 的 Math.random 在循环中生成相同的数字
- wordpress - WordPress 页面更新