我有下一个代码
class MySystem(outerResourse: OuterResourse) extends Actor {
val firstActor = context.actorOf(Props(new FirstActor(outerResourse)), "first")
val secondActor = context.actorOf(Props(new SecondActor(firstActor)), "second")
secondActor ! Go
def receive = {
case x: AnotherMessage => printl(s"another message: $x")
case x => println(x)
}
}
class FirstActor(outerResourse: OuterResourse) extends Actor {
def receive = {
case Test =>
context.parent ! AnotherMessage
sender ! "ok"
}
}
class SecondActor(firstActor: ActorRef) extends Actor {
def receive = {
case Go => firstActor ! Test
case "ok" => println("ok")
}
}
此处OuterResourse
是任何资源 - 文件,互联网连接......
我想查看一个行为,但我很尴尬,我不知道如何检查第二个演员是否会得到一个" ok"和mySystem
演员将得到一个AnotherMessage
class MyTest(_system: ActorSystem) extends TestKit(_system)
with ImplicitSender with FunSpecLike with Matchers {
def this() = this(ActorSystem("myTest"))
val outerResourse = new OuterResourse()
val mySystem = system.actorOf(Props(new MySytem(outerResourse)))
describe("Actors") {
it("should get AnotherMessage message and ok message") {
???
}
}
}
热门检查,secondActor
得到了一个"确定"信息?
答案 0 :(得分:1)
您可以为OutputStream
usnig println
设置自定义Console.withOut
。它可能是模拟并“等待”来自第一个演员的OK消息。但它不是很好......
//编辑:请阅读文档http://doc.akka.io/docs/akka/snapshot/scala/testing.html Akka提供他们测试“框架”