我正在使用 JerseyTest 来测试 RESTful 网络服务。我观察到的一件事是 grizzly 是每种方法的启动/停止,这需要很长时间才能运行我的测试。有没有办法为整个测试班启动/停止灰熊一次。
public class JerseyTestBase extends JerseyTest {
@Override
protected TestContainerFactory getTestContainerFactory()
throws TestContainerException {
return new GrizzlyWebTestContainerFactory();
}
public JerseyTestBase() {
super(new WebAppDescriptor.Builder("xxx.xxx.controller")
.contextPath("test")
.contextParam("contextConfigLocation", "classpath:spring/application-context.xml")
.contextListenerClass(ContextLoaderListener.class)
.requestListenerClass(RequestContextListener.class)
.servletPath("/*")
.servletClass(SpringServlet.class)
.initParam("JSONConfiguration.Builder.rootUnwrapping", "true")
.initParam("com.sun.jersey.api.json.POJOMappingFeature", "false")
.initParam("com.sun.jersey.config.property.MediaTypeMappings", "json : pplication/json")
.initParam("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter")
.initParam("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter")
.build());
}
}
实际测试班
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring/application-context.xml"/*, "classpath:applicationContext-unittest.xml"*/})
public class PurchaseManagerClientControllerTestCase extends JerseyTestBase {}
提前致谢