title: How do I test an Akka actor that sends a message to another actor?
body: <p>I'm using ScalaTest with the Akka TestKit to write unit and integration tests for an actor I've coded to simply send a message to another actor without mutating any internal state. Take this for example:</p>
  
  <pre><code>class MyActor extends Actor {
    val anotherActor = context.actorOf(Props[AnotherActor])
    def receive: Receive = {
      case MyMessage =&gt; anotherActor ! AnotherMessage
    }
  }
  </code></pre>
  
  <p>I want to write a test that confirms that <code>anotherActor</code> processed <code>AnotherMessage</code> as a consequence of <code>MyActor</code> processing <code>MyMessage</code>. The classic example is to use <code>TestActorRef</code> to get at the underlying actor and check for some internal state that should have been affected upon message receipt like so:</p>
  
  <pre><code>val testActorRef = TestActorRef(new MyActor)
  "MyActor" should "change some internal state when it receives MyMessage" in {
    testActorRef ! MyMessage
    testActorRef.underlyingActor.someState shouldBe "altered"
  }
  </code></pre>
  
  <p>But in my case I don't care about such state. In fact, I want to avoid holding any such state. <code>TestProbe</code> wasn't quite what I was looking for either since you still have to register a<code>TestProbe.ref</code> with the actor under test. For the most part, I've looked at all the examples in the Akka documentation on testing (<a href="http://doc.akka.io/docs/akka/snapshot/scala/testing.html" rel="noreferrer">http://doc.akka.io/docs/akka/snapshot/scala/testing.html</a>) but haven't found anything suitable.</p>