reactor / reactor-core

Non-Blocking Reactive Foundation for the JVM

Home Page:http://projectreactor.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StepVerifier usecases

jmayday opened this issue · comments

I'm having difficulty understanding what's the best way I can improve my tests for reactive repositories with StepVerifier.
I know, that I can use it to verify my Mono/Flux return values. But what about setting up test data?

I can do either

 @BeforeEach
    void setup() {
        repo.insert(entities).collectList().block();
    }

or

 @BeforeEach
   void setup() {
        StepVerifier.create(repo.insert(entities)).expectNextCount(10).verifyComplete();
    }

Former seems just fine, but is using the latter any better? Possible pro is that .expectNextCount() will make sure my testdata has been inserted. Or maybe using StepVerifier doesn't make sense in this case at all?

documentation link: https://projectreactor.io/docs/test/release/api/reactor/test/StepVerifier.html

Hey. This question is best suited for Stackoverflow, as it touches on testing best practices. Please use our issue tracker for submitting bug reports or enhancements. To reference some existing discussion, perhaps this issue can be a good start: https://stackoverflow.com/questions/1371940/unit-testing-is-it-a-good-practice-to-have-assertions-in-setup-methods – in my mind, StepVerifier is just a helper to make assertions, so your question is actually more broad and not specific to Reactor.