![](/img/trans.png)
[英]How can I generalize the arity of rxjava2 Zip function (from Single/Observable) to n Nullable arguments without lose its types?
[英]How I can test arguments in Observable RxJava
我有一些方法:
repository.get(arg1, arg2, arg3)
方法返回Single<List<SomeObject>>
我需要測試的是單個被稱為onSubscribe()
與特定的參數。
repository.get(arg1, arg2, arg3)
.test()
.assertSubscribed()
此方法忽略我放在方法repository.get()
。
我如何測試使用某些參數調用的訂閱?
使用Schedulers.trampoline()
使訂閱發生在當前線程上。 然后你可以斷言所需的參數
@Before
fun setup() {
RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }
RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() }
}
這使得代碼在當前線程上運行。 然后你可以斷言args
repository.get(arg1, arg2, arg3)
.test()
.subscribe {
// do the assertions here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.