Search code examples
integration-testingreactive-programmingspring-webfluxstepverifier

How to test a function returning single value like expected onNext actual onComplete.?


I am writing the test cases for one of the Spring Webflux function as:

public Mono<ClassTempKey> getKey(Param param1) {
    return getKeyFromBaseClass();
}

StepVerifier.create(class.getKey(param1)
   .assertNext(key -> {
      assertThat(key.getValue().isEqualTo(value);
   }).verifyComplete();

I am getting the following output

expected: onNext()  actual: onComplete()

The method will return a single key value. Not sure where I am doing wrong.


Solution

  • That would be clearer if you'd post the actual code of getKeyFromBaseClass() method.

    But it looks like that method returns empty Mono, without any value. In reactor empty mono without additional handling returns onComplete signal (not onNext), so you can see it in your test.