2016-11-16 11 views
6

私は先物とモックの先物を実行するためにscalatest % 2.2.6に(理由など)を使用すべきExecutionContext知っていただきたいと思います。ScalatestのExecutionContext

class Foo { 
    def foo: Future[String] = Future.sucessful("B") 
} 

class Bar(foo: Foo) { 
    def bar: Future[String] = foo.foo() 
} 

class MyTest extends WordSpec { 

    implicit val ec: ExecutionContext = ??? // ...global? Why global? Why not? 

    val myMock = mock[Foo] 
    val myBar = new Bar(myMock) 

    "..." in { 
    (myMock.foo _).expects(*).returning(Future.succesful("A")) 
    whenReady(myBar.bar())(_ shouldBe "A") 
    } 
} 

答えて

1

だけscala.concurrent.ExecutionContext.Implicits.globalをインポートし、これが正しく動作するためにあなたのテストで未来のオブジェクトのデフォルトのExecutionContextをロードします。

注:テストで未来を使用するためには、グローバルな暗黙OKです。微調整する場合につき正しいのExecutionContextをconsidere実際のプロジェクトのために。

関連する問題