Eventually

The Eventually trait provides an eventually method, which can repeatedly execute a function passed by name. This is done until the passed function succeeds or the timeout, which was configured, has been exceeded.

The function, which was passed by name, is considered to "succeed" when it returns a result. If the function throws an exception, then eventually will "fail" and would result in the failure of the test.

Let's look at a few examples of eventually. Let's see a successful example first:

val alphabets = 'a' to 'z'
val iterator = alphabets.iterator
eventually { iterator.next should be ('p') }

The default timeout for eventually is 150 milliseconds. This means that if we use the following code, it would result in TestFailedDueToTimeoutException ...

Get Scala Test-Driven Development 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.