我正在尝试编写一个JUnit5测试,该测试断言条件最终将在接下来的15秒内满足。我该如何最好地实现呢?
我正在考虑以下问题:
assertTimeout(ofSeconds(15), () -> {assertThat(condition, is(true));});
但是它应该反复测试条件
答案 0 :(得分:2)
看看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());
...
}