How can I test future failure in a TestSuite with utest?

91 views Asked by At

I would like to know the equivalence of recoverToSucceededIf in scalatest in µtest. In fact, the github page shows the runAsync method which AFAIK is a TestRunner method.

Best regards

1

There are 1 answers

0
Bounkong KHAMPHOUSONE On

I've currently created a trait to extend utest but it surely have a native method. I'll not mark this as an answer as this is just a workaround.

import scala.concurrent.Future

trait UTestExt {
  def recoverToSucceededIf[T <: Throwable: Manifest](f: => Future[Any]): Unit = {
    import scala.concurrent.ExecutionContext.Implicits.global
    f.map(_ => false).recover {
      case _: T => true
      case _    => false
    } foreach (assert(_,
                      manifest[T].runtimeClass.getName + " hasn't been thrown"))
  }
}