Introduction
Here you will find comprehensive documentation for RxTest, a powerful testing framework for ReactiveX in iOS.
Installation
To install RxTest, you can use CocoaPods
, a dependency manager for Swift and Objective-C Cocoa projects.
- Add the following line to your
Podfile
:
pod 'RxTest', '~> 4.0'
- Run the following command:
$ pod install
Usage
To use RxTest in your project, follow these steps:
Step 1: Importing RxTest
In the file where you want to use RxTest, import it by adding the following import statement:
import RxTest
Step 2: Creating a TestScheduler
Before you start writing tests, create an instance of TestScheduler
to simulate the passage of time. This scheduler allows you to control time-based events in your tests.
let scheduler = TestScheduler(initialClock: 0)
Step 3: Writing Tests
You can now write tests for your ReactiveX code. Using the TestScheduler
, you can specify the virtual time at which observable events should occur.
Here’s an example of a simple test:
// Given
let observable = scheduler.createHotObservable([.next(100, "Hello"), .completed(200)])
// When
let observer = scheduler.start { () -> Observable<String> in
return observable.asObservable()
}
// Then
let expectedEvents: [Recorded<Event<String>>] = [
.next(100, "Hello"),
.completed(200)
]
let recordedEvents = observer.events
XCTAssertEqual(recordedEvents, expectedEvents)
Step 4: Running Tests
To run your tests, build and run your test target in Xcode. If all tests pass, you’ll see a success message. Otherwise, any failed tests will be displayed with relevant details.
API Reference
Here you’ll find detailed information about the various classes, methods, and properties provided by RxTest. Use this reference to understand how to best utilize the framework in your projects.
Conclusion
Congratulations! You are now equipped with the knowledge to effectively use RxTest in your ReactiveX projects. Refer to the API reference for further details on available functionality. Happy testing!