我正在尝试写我的第一个ScalaTest
以供关注Actor
object Runner {
def props(race: Race) = Props(classOf[Runner], race)
}
class Runner(race: Race) extends Actor with ActorLogging {
import context.dispatcher
@throws[Exception](classOf[Exception])
override def postRestart(reason: Throwable): Unit = context.parent ! RestartRunner
override def receive: Receive = LoggingReceive {
case Start => {
log.debug("running...")
for (i <- 1 to 3) {
Thread.sleep(200)
}
throw new RuntimeException("MarathonRunner is tired")
}
case StartWithFuture =>
log.debug("I am starting to run")
race.start pipeTo self
case Failure(throwable) => throw throwable
case Stop =>
log.debug("stopping runner")
context.stop(self)
}
}
所以,我愿意
import akka.actor.{Props, ActorSystem}
import akka.testkit.{TestActorRef, TestKit}
import org.scalatest._
class RunnerSpec extends TestKit(ActorSystem("test"))
with WordSpecLike
with MustMatchers {
"A Runner Actor" must {
val runner = TestActorRef(Props(new Runner(new Marathon)))
"receive messages" in {
runner ! Start
runner.under <== says Nothing (see attachment)
}
}
}
但我看到的是
为什么我不拿回来Runner Actor
?