title: Unit testing with Spring and the Jersey Test Framework
body: <p>I'm writing some JUnit-based integration tests for a RESTful web service using JerseyTest. The JAX-RS resource classes use Spring and I'm currently wiring everything together with a test case like the following code example:</p>
  
  <pre><code>public class HelloResourceTest extends JerseyTest
  {
      @Override
      protected AppDescriptor configure()
      {
          return  new WebAppDescriptor.Builder("com.helloworld")
          .contextParam( "contextConfigLocation", "classpath:helloContext.xml")
          .servletClass(SpringServlet.class)
          .contextListenerClass(ContextLoaderListener.class)
          .requestListenerClass(RequestContextListener.class)
          .build();        
      }
  
      @Test
      public void test()
      {
          // test goes here
      }
  }
  </code></pre>
  
  <p>This works for wiring the servlet, however, I'd like to be able to share the same context in my test case so that my tests can have access to mock objects, DAOs, etc., which seems to call for SpringJUnit4ClassRunner.  Unfortunately, SpringJUnit4ClassRunner creates a separate, parallel application context.</p>
  
  <p>So, anyone know how can I create an application context that is shared between the SpringServlet and my test case?</p>
  
  <p>Thanks!</p>