ScalatestContext Exam

I would like to know which ExecutionContext I should use (and why) on scalatest % 2.2.6 to run my futures and fake futures.

 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") } } 
+6
source share
1 answer

Just import scala.concurrent.ExecutionContext.Implicits.global and this will load the default ExecutionContext for Future objects in your tests to work properly.

NOTE: to use Futures in tests, everything is in order. For real projects, it is recommended that you use the ExecutionContext each case.

+1
source

Source: https://habr.com/ru/post/1012383/


All Articles