In 1.x I was using TestSubscriber to perform assertions in unit tests. But it seems that in 2.x is TestObserver the class that we need to use for this matter. Is that correct? And if that's correct, when I should use TestSubscriber?
Thanks.
All reactive types also have a built in test method that can be used.
Very handy. Thanks @vanniktech
You use TestSubscriber with Flowable and TestObserver with Observable. You can test Single, Completable and Maybe by converting them to either Flowable or Observable, but the built-in test()s for these three return TestObserver.
Thanks @akarnokd
In 2.x @akarnokd mentioned that the built-in return for Single, Completable and Maybe is TestSubscriber but it looks like it actual default for Completable is now TestObserver
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final TestObserver<Void> test() {
TestObserver<Void> ts = new TestObserver<Void>();
subscribe(ts);
return ts;
}
@davidargylethacker Thanks, edited my comment to define the correct type.
Thanks @akarnokd
Most helpful comment
You use
TestSubscriberwithFlowableandTestObserverwithObservable. You can testSingle,CompletableandMaybeby converting them to eitherFlowableorObservable, but the built-intest()s for these three returnTestObserver.