Verifying the method invocation within the specified time

Testing asynchronous code is a very broad topic, and we will not go into great details here. The fact is that the best way to test this kind of code is to make it synchronous and test it separately; this is crucial in terms of performance and execution time of unit tests. Imagine having quite a few such cases where you have to wait for a second or so for the test to complete. It would definitely increase the overall time of your tests and you wouldn't want that to happen.

You might, however, have a business requirement where it is crucial to verify whether some particular business feature was executed within the specified time (for example, a request has been sent within one second). In ...

Get Mockito Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.