There is a way to indirectly access both threads that the observable is running on and which can be observed, which means that you can really verify that the Observable uses the correct schedulers.
We restrict ourselves to checking threads by name. Fortunately, the streams used by Schedulers.io() are called with a consistent prefix with which we can map. Here (complete?) Is a list of planners that have unique link prefixes:
Schedulers.io() - RxCachedThreadSchedulerSchedulers.newThread() - RxNewThreadSchedulerSchedulers.computation() - RxComputThreadPool
To verify that an Observable has been subscribed to an I / O stream :
To check the observable observable in the computation flow , you can use TestSubscriber#getLastSeenThread to access the last thread used for observation.
TestSubscriber<Object> subscriber = TestSubscriber.create(); UseCase usecase = new UseCase(Observable.empty(), Schedulers.computation()) usecase.execute().subscribe(subscriber);
There is no need for third-party libraries or ridicule, although I use AssertJ for the free startsWith statement.
source share