我正在尝试编写一个 JUnit5 测试,断言最终在接下来的 15 秒内满足条件。我怎样才能最好地实现这一点?
我在想这个问题:
    assertTimeout(ofSeconds(15), () -> {assertThat(condition, is(true));});
Run Code Online (Sandbox Code Playgroud)
但要反复测试条件
Geo*_*iou 10
看看Awaitility,它有您正在寻找的功能。(文档在这里)
@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());
  ...
}
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           6102 次  |  
        
|   最近记录:  |