Unit testing concentrates on a function to find out if the expected result matches with the actual result or not, under various probable situations. To test reactive components, we will start with a simple Observable which emits items, and tests whether the expected result matches with the actual or not. We will create Observable using the just() operator, emitting three items. We are also going to create a consumer which will add the items to an ArrayList instance. Later on, using the assertXXX() methods, we will cross-check the actual and expected values for the following test cases:
- The list is not null
- The list size is equal to three as our Observable is emitting three items
- The second emitted item has the value equal to the actual value emitted by the Observable
The code for the preceding test cases is as follows:
public...