我的单元测试有一些问题。我想用我的代码做一些单元测试,但是发现了这样的错误。我一直在寻找堆栈溢出的解决方案,但还没有得到解决方案。
view.setDetailLeague(
[]
);
-> at com.example.submission3kotlin.TestAnother.getAnotherTest(TestAnother.kt:44)
Actual invocations have different arguments:
view.setDetailLeague(
[League(dateFirstEvent=2000-08-18, idCup=0, idLeague=4328, idSoccerXML=1, intFormedYear=1992, strBadge=https://www.thesportsdb.com/images/media/league/badge/i6o0kh1549879062.png, strBanner=https://www.thesportsdb.com/images/media/league/banner/4m3g4s1520767740.jpg, strComplete=yes, strCountry=England, strDescriptionCN=英格兰足球超级联赛(英语:Premier League),简称英超,過往冠名為巴克萊超級聯賽(Barclays Premier League)]
);
这是我的主持人
class DetailLeaguePresenter(val view: DetailLeagueContract.View, private val scheduler: SchedulerProvider): DetailLeagueContract.Presenter {
override fun getDetailLeague(id: String) {
val retrofit = RetrofitClient.getClient()
.create(UserService::class.java)
CompositeDisposable().add(
retrofit.responseDetailLeague(id)
.observeOn(scheduler.ui())
.subscribeOn(scheduler.io())
.subscribe(
{
view.setDetailLeague(it.leagues)
}, { error -> Log.e("Error", error.message) }
)
)
}
}
我的模拟测试代码:
class TestAnother {
@Mock
lateinit var view: DetailLeagueContract.View
@Mock
private val retrofitClient = RetrofitClient.getClient().create(UserService::class.java)
@Mock
lateinit var scheduler: SchedulerProvider
private lateinit var mPresenter: DetailLeaguePresenter
@Before
fun setupEnv(){
MockitoAnnotations.initMocks(this)
scheduler = TestSchedulerProvider()
mPresenter = DetailLeaguePresenter(view, scheduler)
}
@Test
fun getAnotherTest(){
val data: MutableList<League> = mutableListOf()
val response = DetailLeague(data)
val id = "4328"
`when`(retrofitClient.responseDetailLeague(id)).thenReturn(Observable.just(response))
mPresenter.getDetailLeague(id)
verify(view).setDetailLeague(response.leagues)
}
}
有人可以帮助我吗?预先谢谢你