简体   繁体   English

Mono.then() 在测试中未执行

[英]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"));

  1. 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 应用程序和测试是否使用相同的数据运行?

  2. " 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.

相关问题 Mono 未按计划执行 - Mono not executing with schedule 通过集成测试执行生产代码时的@Autowired 字段 null - @Autowired field null when executing production code via integration tests 执行集成测试时,不同的数据库配置取决于环境 - Different database configurations depending on environment when executing integration tests 升级到 Spring Boot 2.7 时测试失败 - “CommandAcceptanceException:执行 DDL 时出错” - Tests failing when upgrading to Spring Boot 2.7 - "CommandAcceptanceException: Error executing DDL" Gradle执行测试的速度非常慢,因为它为套件增加了很多测试 - Gradle is executing tests terribly slow because it is adding to much tests to the suite 使用Spring Reactive时如何验证Mono - How to validate Mono when using Spring Reactive Java 中的 Mono 类:是什么,何时使用? - Mono class in Java: what is, and when to use? 什么时候交易 Mono.fromCallback ? (反应性) - When is the deal Mono.fromCallback ? (reactive) 使用 Spring Webflux 时在后台运行 Mono 并返回响应 - Running a Mono in background while returning a response when using Spring Webflux 何时使用单声道 <List<Object> &gt;以及当助焊剂 <Object> 用于RestController方法 - When to use Mono<List<Object>> and when Flux<Object> for RestController method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM