2 回答
TA贡献1802条经验 获得超6个赞
您需要添加一个测试容器工厂。
ResourceExtension resources = ResourceExtension.builder()
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
.addResource(new MyResource())
.build();
如果您使用 Maven:
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
<!-- version>${jersey.version}</version -->
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
TA贡献1874条经验 获得超12个赞
我有一个类似的问题,也用一个测试容器工厂解决了它。但是,我的方法与 jgl 之前发布的方法不同。
public class SessionRestTest extends JerseyTest {
@Override
protected TestContainerFactory getTestContainerFactory() {
// standard servername and port is localhost:9998
return new GrizzlyWebTestContainerFactory();
}
@Override
protected DeploymentContext configureDeployment() {
ResourceConfig config = new ResourceConfig(SessionRest.class);
return ServletDeploymentContext.forServlet(
new ServletContainer(config)).build();
}
private Response get() {
return target("/session/logout").request().get();
}
@Test
public void testRedirectURL() {
Response response = get();
assertEquals("should return status 200", HttpStatus.OK_200, response.getStatus());
}
}
添加回答
举报