How to test methods that return Future?

前端 未结 6 2123
时光说笑
时光说笑 2021-02-07 08:25

I\'d like to test a method that returns a Future. My attempts were as follows:

import  org.specs2.mutable.Specification
import scala.concurrent.Exec         


        
6条回答
  •  醉梦人生
    2021-02-07 08:49

    Took me awhile to find this so thought I'd share. I should've read the release notes. In specs2 v3.5, it is required to use implicit ExecutionEnv to use await for future. This can also be used for future transformation (i.e. map) see http://notes.implicit.ly/post/116619383574/specs2-3-5.

    excerpt from there for quick reference:

    import org.specs2.concurrent.ExecutionEnv
    
    class MySpec extends mutable.Specification {
      "test of a Scala Future" >> { implicit ee: ExecutionEnv =>
        Future(1) must be_>(0).await
      }
    }
    

提交回复
热议问题