O'Reilly logo

Reactive Programming With Java 9 by Tejaswini Mandar Jog

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The TestObserver class

The RxJava library also provides TestObserver, which facilitates testing of a non-backpressured Observable such as Single, Maybe, and Completable. An Observer records the events and allows making assertions about them. The developers can override methods such as onSubscribe(), onNext(), onComplete(), onSuccess(), onError(), and cancel().

Let's use TestObserver to test the Observable that we created in the earlier application. We will create an instance of TestObserver, and then pass it to the subscribe() method of the Observable to collect the emitted items. With the help of the assertXXX() method provided by TestObserver, we will carry out testing as follows:

 @Test public void test_just_new() { Observable<Integer> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required