Class DropwizardAppRule<C extends Configuration>

  • Type Parameters:
    C - the configuration type
    All Implemented Interfaces:
    org.junit.rules.TestRule

    @Deprecated
    public class DropwizardAppRule<C extends Configuration>
    extends org.junit.rules.ExternalResource
    Deprecated.
    Deprecated since Dropwizard 2.0.0. Please migrate to JUnit 5 and DropwizardAppExtension.
    A JUnit rule for starting and stopping your 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).

    Using DropwizardAppRule at the suite level can speed up test runs, as the application is only started and stopped once for the entire suite:

     @RunWith(Suite.class)
     @SuiteClasses({FooTest.class, BarTest.class})
     public class MySuite {
       @ClassRule
       public static final DropwizardAppRule<MyConfig> DROPWIZARD = new DropwizardAppRule<>(...);
     }
     

    If the same instance of DropwizardAppRule is reused at the suite- and class-level, then the application will be started and stopped once, regardless of whether the entire suite or a single test is executed.

     public class FooTest {
       @ClassRule public static final DropwizardAppRule<MyConfig> DROPWIZARD = MySuite.DROPWIZARD;
    
       public void testFoo() { ... }
     }
    
     public class BarTest {
       @ClassRule public static final DropwizardAppRule<MyConfig> DROPWIZARD = MySuite.DROPWIZARD;
    
       public void testBar() { ... }
     }