title: Testing actors using dependency injection in play framework 2.4.x
body: <p>How do I test an actor that is created by dependency injection? In my application I can get an ActorRef by named injection:</p>
  
  <pre><code>public MyClass {
      @Inject
      @Named("ping")
      ActorRef mPingRef;
  }
  </code></pre>
  
  <p>How do I get this reference in my tests? </p>
  
  <p>This is my actor:</p>
  
  <pre><code>public class PingActor extends UntypedActor {
      @Inject
      public PingActor(Configuration configuration) {
           ... // Use config
      }
  
  
      @Override
      public void onReceive(Object message) throws Exception {
          if (message instanceof Ping) {
              getSender().tell(new Pong(), getSelf());
          }
      }
  
      public static class Ping {}
      public static class Pong {}
  }
  </code></pre>
  
  <p>I have configured my application with my own module:</p>
  
  <pre><code>public class MyModule extends AbstractModule implements AkkaGuiceSupport {
      private final Configuration mConfig;
  
      public MyModule(Environment environment, Configuration configuration){
          this.mConfig = configuration;
      }
  
      @Override
      protected void configure() {
          bindActor(PingActor.class, "ping");
      }
  }
  </code></pre>
  
  <p>The module is enabled in application.conf:</p>
  
  <pre><code>play.modules.enabled += "com.my.package.MyModule"
  </code></pre>