Class GuiceyAppRule<C extends io.dropwizard.core.Configuration>

java.lang.Object
org.junit.rules.ExternalResource
ru.vyarus.dropwizard.guice.test.GuiceyAppRule<C>
Type Parameters:
C - configuration type
All Implemented Interfaces:
org.junit.rules.TestRule

public class GuiceyAppRule<C extends io.dropwizard.core.Configuration> extends org.junit.rules.ExternalResource
A JUnit rule for starting and stopping your guice application at the start and end of a test class.

By default, the Application will be constructed using reflection to invoke the nullary constructor. If your application does not provide a public nullary constructor, you will need to override the newApplication() method to provide your application instance(s).

Based on DropwizardAppRule, but doesn't start jetty and as a consequence jersey and guice web modules not initialized. Emulates managed objects lifecycle.

Suppose to be used for testing internal services business logic as lightweight alternative for dropwizard rule.

Since:
23.10.2014
See Also:
  • for junit 5 alterantive
  • Constructor Details

    • GuiceyAppRule

      public GuiceyAppRule(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, io.dropwizard.testing.ConfigOverride... configOverrides)
  • Method Details

    • getConfiguration

      public C getConfiguration()
    • getApplication

      public <A extends io.dropwizard.core.Application<C>> A getApplication()
    • getEnvironment

      public io.dropwizard.core.setup.Environment getEnvironment()
    • getInjector

      public com.google.inject.Injector getInjector()
    • getBean

      public <T> T getBean(Class<T> type)
    • newApplication

      protected io.dropwizard.core.Application<C> newApplication()
    • before

      protected void before() throws Throwable
      Overrides:
      before in class org.junit.rules.ExternalResource
      Throws:
      Throwable
    • after

      protected void after()
      Overrides:
      after in class org.junit.rules.ExternalResource