O'Reilly logo

Scala Test-Driven Development by Gaurav Sood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required