[英]Mono.then() not executing when in tests
I'm trying to test the following code using integration tests:我正在尝试使用集成测试来测试以下代码:
return ((Mono<Object>) joinPoint.proceed()).then(provider.getAuthor().flatMap((author) -> {
Arrays.stream(joinPoint.getArgs())
.forEach(arg -> javers.commitShallowDeleteById(author, InstanceIdDTO.instanceId(arg.toString(), deletedEntity)));
return Mono.empty();
}));
jointPoint.proceeed()
Always returns a Mono<Void>
so that's why i'm using then()
. jointPoint.proceeed()
总是返回Mono<Void>
所以这就是我使用then()
的原因。
When running the app in debug mode if i place a breakpoint inside the flatmap i can see it passes through there, however if i run it in a @SpringBootTest
in no longer passes inside the flatmap.在调试模式下运行应用程序时,如果我在平面图中放置一个断点,我可以看到它通过那里,但是如果我在
@SpringBootTest
中运行它,则不再在平面图中通过。
Test configuration:测试配置:
@DirtiesContext
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Provider: when(authorProvider.getAuthor()).thenReturn(Mono.just("Author"));
提供者:
when(authorProvider.getAuthor()).thenReturn(Mono.just("Author"));
Maybe provider.getAuthor()
returns no value (a Mono.empty()
) when you run your test?运行测试时,
provider.getAuthor()
可能没有返回值(一个Mono.empty()
)?
A flatMap
needs a value to operate on. flatMap
需要一个值来操作。 If there is no value, it won't be called.如果没有值,则不会调用它。 You can add a
doOnComplete()
call and see whether it is triggered when the sequence completes.您可以添加一个
doOnComplete()
调用并查看它是否在序列完成时触发。
Are the web application and the test running with the same data? web 应用程序和测试是否使用相同的数据运行?
" Nothing happens until you subscribe " “在您订阅之前什么都不会发生”
You can add a doOnSubscribe()
call and see whether it is triggered and when, when running the test.您可以添加一个
doOnSubscribe()
调用并查看它是否被触发以及何时触发,何时运行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.