Search code examples
scalascalatest

Scalatest: waiting for an assertion to become true


Is there anything that exists in scalatest that will wait for a period of time for an assertion to become true?

So, for example, if I have a thread that computes something asynchronously, I want to wait in my test for the computation to equal the expected value.


Solution

  • You most likely want Eventually:

    https://www.scalatest.org/scaladoc/3.2.6/org/scalatest/concurrent/Eventually.html

    But if your computation is inside a future, you would probably want to use one of the Futures subtraits:

    https://www.scalatest.org/scaladoc/3.2.6/org/scalatest/concurrent/Futures.html