The Observable emits an item, an error, or a notification to Observer. Testing of items can be done by checking the final result of the subscription using TestObserver or TestSubscriber with methods such as assertValue() or assertResult(), which we have just discussed. The RxJava library also provides methods for testing the notifications sent by the Observable as given in the following table:
Name of the method | Description | Class providing the method |
assertNotSubscribed() | This method asserts that the method onSubscribe() has not been invoked | TestObserver |
assertSubscribed() | This method asserts that the method onSubscribe() will be invoked only once | TestObserver |
assertComplete() | This method asserts that TestObserver or TestSubscriber has received exactly one onComplete event | BaseTestConsumer |
assertNoErrors() | The assertNoErrors() method asserts that... |