在订阅之前处理测试观察者的用例是什么?
What would be a use case for disposing a test observer before subscription?
Observable class 有这个方法:
public final TestObserver<T> test(boolean dispose)
在订阅可观察对象之前处理测试观察者的用例是什么?
如果您要构建自定义运算符,则必须确保它符合反应流 specification. For example, it states the following for Subscription:
6 - After the Subscription is cancelled, additional Subscription.request(long n) MUST be NOPs.
7 - After the Subscription is cancelled, additional Subscription.cancel() MUST be NOPs.
该 dispose 方法只是 convenient method to help you to test these scenarios. You can check how it's being used in the RxJava code base here 单元测试运算符,如 Cache、Concat、Timeout..
这里是超时运算符的example:
@Test
public void disposeWhenFallback() {
TestScheduler sch = new TestScheduler();
SingleSubject<Integer> subj = SingleSubject.create();
subj.timeout(1, TimeUnit.SECONDS, sch, Single.just(1))
.test(true)
.assertEmpty();
assertFalse(subj.hasObservers());
}
在观察者被释放后订阅它时检查流是否为空。
Observable class 有这个方法:
public final TestObserver<T> test(boolean dispose)
在订阅可观察对象之前处理测试观察者的用例是什么?
如果您要构建自定义运算符,则必须确保它符合反应流 specification. For example, it states the following for Subscription:
6 - After the Subscription is cancelled, additional Subscription.request(long n) MUST be NOPs.
7 - After the Subscription is cancelled, additional Subscription.cancel() MUST be NOPs.
该 dispose 方法只是 convenient method to help you to test these scenarios. You can check how it's being used in the RxJava code base here 单元测试运算符,如 Cache、Concat、Timeout..
这里是超时运算符的example:
@Test
public void disposeWhenFallback() {
TestScheduler sch = new TestScheduler();
SingleSubject<Integer> subj = SingleSubject.create();
subj.timeout(1, TimeUnit.SECONDS, sch, Single.just(1))
.test(true)
.assertEmpty();
assertFalse(subj.hasObservers());
}
在观察者被释放后订阅它时检查流是否为空。