title: Dropwizard Integrated Testing with TestResource
body: <p>Does anyone knows how to add a test Resource (i.e. one that is only for testing purposes and not added in run() method of the app)?</p>
  
  <p>Here is an example: </p>
  
  <pre><code>public class MyTest {   
      @ClassRule
      public static final DropwizardAppRule&lt;TestConfiguration&gt; RULE =
              new DropwizardAppRule&lt;TestConfiguration&gt;(MyApp.class, "my-app-config.yaml");
  
  
      @BeforeClass
      public static void setUpBeforeClass() throws Exception
      {
          MyTest.RULE.getEnvironment().jersey().register(new JustForTestingResource());
      }
  
  
      @Test
      public final void testTestResource()
      {
          Client client = new Client();
  
          ClientResponse response = client.resource(
              String.format("http://localhost:%d/rest/v1/test", RULE.getLocalPort()))
              .get(ClientResponse.class);
  
          assertThat(response.getStatus(), is(200));   
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class JustForTestingRessource {
  
  
      @GET
      @Path("test")
      @Produces(MediaType.APPLICATION_JSON)
      public Response getInTestResource()
      {
          return Response.status(Status.OK).type(MediaType.TEXT_PLAIN).entity("get @Path(\"test\") is ok").build();
      }
  }
  </code></pre>
  
  <p>My problem is that the added resource is not added and I get resource not found 404 error response. It seems that I am registering the new resource after resource publishing and there is no refresh inside Dropwizard after start. </p>
  
  <p>I dont want to extend my Application class and I dont want to insert test code into my real application code. Does anyone knows how to register the test resource without registering it in run() method of the Application?</p>
  
  <p>This works, but a new class is needed:</p>
  
  <pre><code>public class TestService extends MyService{
  
  
      @Override
      public void run(
          TestConfigurationconfiguration,
          Environment environment) throws ClassNotFoundException
      {       
          environment.jersey().register(new JustForTestingRessource());
          super.run(configuration,environment);
      }
  
  }
  </code></pre>
  
  <p>Call in JUnit as already known:</p>
  
  <pre><code>@ClassRule
  public static DropwizardAppRule&lt;TestConfiguration&gt; RULE =
          new DropwizardAppRule&lt;TestConfiguration&gt;(TestService.class, "my-app-config.yaml");
  </code></pre>