We've covered blockingSubscribe() and several blocking operators in this chapter so far. 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 also would 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 your 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...