我该如何修复这个 Akka 单元测试?

How do I fix this Akka unit test?

我从 Python 来到 Scala,正在尝试理解 test framework integration by modifying the examples in the documentation. I've pastebinned my main.scala file and maintests.scala 文件。演员使用键入的消息。它接受 MoveRequest 并回复 MoveAction。 IntelliJ 抱怨存在类型不匹配并且 probe.expectMessage(character.MoveAction("north")) 应该更改为 MoveRequest,我不明白这是应该探测的,而不是预期的。编译器抱怨类型不匹配。我究竟做错了什么?有没有更好的测试方法?

需要将 TestProbe 输入为您发送的消息类型。

final case class MoveRequest(message: String,  response: ActorRef[MoveAction])

此处响应 actor 接收的消息类型是 MoveAction,因此在您的测试示例中,您需要一个 MoveAction 类型的 TestProbe 来测试发送给它的消息。

  val probe = testKit.createTestProbe[MoveAction]()

由于测试探针不是针对被测角色,而是针对 MoveRequest 消息中的角色。