我正在为使用JerseyTest的REST风格的Web服务编写一些基于JUnit的集成测试。在JAX-RS资源类使用Spring和我目前正在与一个测试用例状引线evernthing一起以下:使用Spring和Jersey测试框架进行单元测试
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
}
}
这适用于布线servlet的,但是,我希望能够分享在我的测试用例中使用相同的上下文,以便我的测试可以访问模拟对象,DAO等,这似乎要求SpringJUnit4ClassRunner。不幸的是,SpringJUnit4ClassRunner创建了一个单独的并行应用程序上下文。
因此,任何人都知道如何创建一个在SpringServlet和我的测试用例之间共享的应用程序上下文?
谢谢!
[此其他示例代码](https://github.com/yamsellem/jersey-basics/blob/master/src/test/java/com/xebia/resource/ProductResourceJacksonTest.java)允许选择灰熊或Jetty进行部署。 Grizzly速度稍快一些,但不能使用web.xml(因此它必须由代码配置)。 –