[英]How I can test arguments in Observable RxJava
I have some method:我有一些方法:
repository.get(arg1, arg2, arg3)
Method return Single<List<SomeObject>>
方法返回
Single<List<SomeObject>>
I need testing that Single was called onSubscribe()
with specific arguments.我需要测试的是单个被称为
onSubscribe()
与特定的参数。
repository.get(arg1, arg2, arg3)
.test()
.assertSubscribed()
This method ignores arguments which I put in method repository.get()
.此方法忽略我放在方法
repository.get()
。
How I can test that subscribe called with certain arguments?我如何测试使用某些参数调用的订阅?
use Schedulers.trampoline()
to make the subscription occur on the current thread.使用
Schedulers.trampoline()
使订阅发生在当前线程上。 then you can assert the required args然后你可以断言所需的参数
@Before
fun setup() {
RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }
RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() }
}
this makes the code run on the current thread.这使得代码在当前线程上运行。 then you can assert the args
然后你可以断言args
repository.get(arg1, arg2, arg3)
.test()
.subscribe {
// do the assertions here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.