Testing in RxSwift
RxTest
and RxBlocking
are part of the RxSwift
repository but are made available via separate pods and hence require separate imports. RxTest
provides useful additions for testing Rx code, including TestScheduler
, which is a virtual time scheduler and methods for adding events at precise time intervals, whereas RxBlocking
enables converting a regular Observable sequence to a blocking observable, which blocks the thread it's running on until the observable sequence completes or a specified timeout is reached. This makes testing asynchronous operations much easier.
RxTest
As specified earlier, RxTest
is part of the same repository as RxSwift
, and there is one more thing to know about RxTest
before we dive into some RxTesting
—RxTest
exposes two types of Observable for testing purposes:
HotObservables
ColdObservables
HotObservables
replay events at specified times using a test scheduler regardless of there being any subscribers.
ColdObservables
work more like regular Observables...