JUnit 5 has Assertions.assertTimeout(Duration, Executable)
/assertTimeoutPreemptively()
(please read Javadoc of each to understand the difference) and Mockito has verify(mock, timeout(millisecs).times(x))
.
Assertions.assertTimeout(Duration.ofMillis(1000), () ->
myReactiveService.doSth().subscribe()
);
And:
Mockito.verify(myReactiveService,
timeout(1000).times(0)).doSth(); // cannot use never() here
Timeout may be nondeterministic/fragile in pipelines. So be careful.