Scala 未找到:值expectMsg
我对Akka组件进行了以下测试:Scala 未找到:值expectMsg,scala,akka,Scala,Akka,我对Akka组件进行了以下测试: import somePackage.SomeActor import akka.actor.{ActorSystem, Props} import org.scalatest.{FlatSpec, Matchers} class SomeActorSpec extends FlatSpec with Matchers { val system = ActorSystem() val someActorRef = system.actorOf(Pro
import somePackage.SomeActor
import akka.actor.{ActorSystem, Props}
import org.scalatest.{FlatSpec, Matchers}
class SomeActorSpec extends FlatSpec with Matchers {
val system = ActorSystem()
val someActorRef = system.actorOf(Props(classOf[SomeActor]))
it should "check the id" in {
someActorRef ! CheckIfJobIsRunning(UUID.randomUUID)
expectMsg(SomeOtherMessage(List()))
}
}
我得到一个错误:
not found: value expectMsg
[error] expectMsg(SomeOtherMessage(List()))
我有两个问题:
1.如何使用expectMsg
2.我在哪里定义测试类应该接收的,
SomeOtherMessage
。您的示例应该如下所示:
class SomeActorSpec extends FlatSpec with Matchers {
it should "check the id" in new Scope {
someActorRef ! CheckIfJobIsRunning(UUID.randomUUID)
expectMsg(SomeOtherMessage(List()))
}
abstract class Scope extends TestKit(ActorSystem()) {
val someActorRef = system.actorOf(Props(classOf[SomeActor]))
}
}
更多信息请访问。关于你的问题:
expectMsg
测试参与者在收到CheckIfJobIsRunning
CheckIfJobIsRunning
、SomeOtherMessage
以及包含与参与者相关的所有消息的协议类文件中的其他消息。我个人使用actor的companion对象来指定所有这些消息