Class TestKitJunitResource

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public final class TestKitJunitResource
    extends org.junit.rules.ExternalResource
    A Junit external resource for the ActorTestKit, making it possible to have Junit manage the lifecycle of the testkit. The testkit will be automatically shut down when the test completes or fails.

    Note that Junit is not provided as a transitive dependency of the testkit module but must be added explicitly to your project to use this.

    Example:

    
     public class MyActorTest {
       @ClassRule
       public static final TestKitResource testKit = new TestKitResource();
    
       @Test
       public void testBlah() throws Exception {
               // spawn actors etc using the testKit
               ActorRef<Message> ref = testKit.spawn(behavior);
       }
     }
     

    By default config is loaded from application-test.conf if that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries. The application.conf of your project is not used in this case. A specific configuration can be passed as constructor parameter.

    • Constructor Detail

      • TestKitJunitResource

        public TestKitJunitResource​(ActorTestKit _kit)
      • TestKitJunitResource

        public TestKitJunitResource()
        Config loaded from application-test.conf if that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries. The application.conf of your project is not used in this case.
      • TestKitJunitResource

        public TestKitJunitResource​(ActorSystem<?> system)
        Use a custom ActorSystem for the actor system.
      • TestKitJunitResource

        public TestKitJunitResource​(java.lang.String customConfig)
        Use a custom config for the actor system.
      • TestKitJunitResource

        public TestKitJunitResource​(com.typesafe.config.Config customConfig)
        Use a custom config for the actor system.
      • TestKitJunitResource

        public TestKitJunitResource​(com.typesafe.config.Config customConfig,
                                    TestKitSettings settings)
        Use a custom config for the actor system, and a custom TestKitSettings.