mardi 18 octobre 2016

RxJava test Observable

There is something like TestSubscriber. It has very useful functions like awaitTerminalEvent(), getOnNextEvents(), etc.

Is there an equivalent of TestSubscriber for Observable that might be pinned to some observable in the middle of sequence?

I would like to test some specific cases, one of which is:

  • I have a class that accepts Observable in constructor. One of it's methods invokes that Observable inside onErrorResumeNext operator. So executing the main Observable under specific conditions might invoke tested Observable. Something like assertExecuted is needed.

  • In the case described above I would like to test Thread the Observable is executed on.

  • I would like to know, what Observable returned based on it's input.

Each of those cases require workarounds like:

observable
  .doOnNext(o -> {
      // Observable was given a value
   });

If there is no nice way already available, how to make the call above cleaner?

Aucun commentaire:

Enregistrer un commentaire