title: Scala and Akka - Testing actors as a system with Akka Testkit
body: <p>In my Scala application say I have Actor <code>A</code> and Actor <code>B</code>. I want to devise a test case in ScalaTest that would allow me to send a message to Actor <code>A</code> and see what message it sends to Actor <code>B</code> in order to see if <code>A</code> is properly processing it's data and sending the right message to <code>B</code>. How would one test this? It took me a long time to get this cooked up on my own...but it does seem to mostly work. </p>
  
  <pre><code>class A extends Actor { ... }
  
  class B extends Actor { ... }
  
  class C(p: TestProbe) extends B {
    override def receive = {
      LoggingReceive {
        case x =&gt;
          println(x.toString)
          p.ref ! x
      }
    }
  }
  
  case class MsgToB(...)
  
  // Spec class which extends TestKit
  "A" should {
    "send the right message to B" {
      val p = TestProbe()
      val a = TestActorRef[A]
      val c = TestActorRef(Props(new C(p)))
  
      // Assume A has a reference to C. Not shown here.
      a ! msg
      // Assert messages
      p.expectMsgType[MsgToB]
    }
  }
  </code></pre>
  
  <p>Is this the best means of doing this? Is there a better practice?</p>