Unit testing Reactor pipelines is quite hard. This is because Reactor declares behaviors rather than states that can be validated. Fortunately, Reactor comes with utility classes that can assist in unit testing. The testing utilities are bundled in the reactor-test component. reactor-test provides us with the following three components:
- StepVerifier: Allows us to validate a pipeline configuration and operators
- TestPublisher: Allows us to produce test data to enable testing operators
- PublisherProbe: Enables us to validate an existing publisher
Before we proceed, let's first add reactor-test to our build.gradle. We do not need to specify the version of this as that is defined by the org.springframework.boot plugin: ...