We've so far covered blockingSubscribe() and several blocking operators in this chapter. While you can use these blocking tools to do simple assertions, there is a much more comprehensive way to test reactive code than simply blocking for one or more values. After all, we should do more than test onNext() calls. We also have onComplete() and onError() events to account for! It would also be great to streamline testing other RxJava events, such as subscription, disposal, and cancellation.
So let's introduce the TestObserver and TestSubscriber, your two best friends in testing RxJava applications.
TestObserver and TestSubscriber are a treasure trove of convenient methods to aid testing, many of which assert that certain events have occurred or specific values were received. There are also blocking methods, such as awaitTerminalEvent...