title: akka: how to test that an actor was stopped
body: <p>I am wondering what the canonical way is of testing whether an actor has stopped in akka. Here is an example of how I am currently doing; I'm worried I'm over complicating it.</p>
  
  <pre><code>import akka.actor.{Terminated, Actor, Props, ActorSystem}
  import akka.testkit.TestProbe
  
  class MyActor extends Actor {
    import MyActor._
    override def receive: Receive = {
      case Stop =&gt; context.stop(self)
    }
  }
  
  object MyActor {
    def props = Props(new MyActor)
    case object Stop
  }
  
  
  object MyActorSpec {
  
    val system = ActorSystem()
    val myActor = system.actorOf(MyActor.props)
    val testProbe = TestProbe()
  
    case object MyActorStopped
  
    val watcher = system.actorOf(Props(new Actor {
      context.watch(myActor)
      override def receive: Actor.Receive = {
        case Terminated(`myActor`) =&gt; testProbe.ref ! MyActorStopped
      }
    }))
  
    myActor ! MyActor.Stop
    testProbe.expectMsg(MyActorStopped)
  }
  </code></pre>