我對斯卡拉相當新,所以請溫柔。與斯卡拉Akka演員單元測試
在我正在構建的應用程序中,我使用了Akka actors,並且想編寫一些單元測試。我碰到這official documentation for writing unit tests for Akka actors
但我不明白它應該如何工作。特別是,
val actorRef = TestActorRef(new MyActor)
// hypothetical message stimulating a '42' answer
val future = actorRef ? Say42
val Success(result: Int) = future.value.get
result must be(42)
當我嘗試,我得到not found: value Success
,這並不奇怪。
我隨後發現this example of how to test Scala actors
val actorRef = TestActorRef[TickTock]
implicit val timeout = Timeout(5 seconds)
val future = (actorRef ? new Tick("msg")).mapTo[String]
val result = Await.result(future, timeout.duration)
Assert.assertEquals("processed the tick message", result)
,這固然可能是老了,但很容易理解和更接近時,我想用什麼期貨我通常使用,最重要的工作。它確實需要我聲明像ActorSystem,超時等一些暗示,這似乎並不是官方的情況...
如果可能,我想使用提出的方法官方文檔,所以如果有人能幫助我理解它是如何工作的(特別是成功位)以及如何使用它,我將不勝感激。
你有進口像'scala.util._'或'scala.util.Success '? – 4lex1v