gpt4 book ai didi

java - 如何断言该条件最终得到满足?

转载 作者:行者123 更新时间:2023-12-01 14:21:19 24 4
gpt4 key购买 nike

我正在尝试编写一个 JUnit5 测试,断言在接下来的 15 秒内最终满足条件。我怎样才能最好地实现它?

我在想这个问题:

    assertTimeout(ofSeconds(15), () -> {assertThat(condition, is(true));});

但它应该反复测试条件

最佳答案

看看Awaitility ,它具有您正在寻找的功能。 ( docs here )

@Test
public void updatesCustomerStatus() throws Exception {

// Publish an asynchronous event:
publishEvent(updateCustomerStatusEvent);
// Awaitility lets you wait until the asynchronous operation completes:
await().atMost(5, SECONDS).until(customerStatusIsUpdated());
...
}

关于java - 如何断言该条件最终得到满足?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53504495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com