找不到:value expectMsg

时间:2016-12-06 09:51:54

标签: 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(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哪个应该由测试类接收?

1 个答案:

答案 0 :(得分:2)

使用static int hornerUmkehrungRekursiv(int z, int q) { if (z == 0) { return 0; } else { int v = z % q; int r = (hornerUmkehrungRekursiv(z / q, q) * 2) + v; System.out.print(v); return r; } } 范围。您的示例应如下所示:

TestKit

docs中的更多信息。关于你的问题:

  1. 使用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时向其他演员发送SomeOtherMessage
  2. 在类似协议的文件中定义CheckIfJobIsRunningCheckIfJobIsRunning和其他文件,其中包含与您的演员相关的所有消息。我个人使用actor的伴侣对象来指定所有这些消息。