实际上,我正在尝试用泽西测试框架来测试我的泽西web服务。我使用的web服务器是Websphere 7和java 6,这是我的项目要求,我不能升级java版本。
我的问题是如何为我的web服务构建单元测试。我想在WebSphere上测试它们,但是我不知道如何设置像junit这样的单元测试环境。
更具体地说,我只需要从测试类调用一个URL并检查响应。但是如何从websphere上的test类调用URL,我没有得到它的方向。
发布于 2015-08-14 09:33:24
查看一下泽西测试框架的文档。
您首先需要的是支持的容器依赖关系之一。其中任何一个都会拉进核心框架。
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
<version>2.19</version>
<scope>test</scope>
</dependency>
然后需要一个扩展JerseyTest
的测试类。您可以重写Application configure()
以提供ResourceConfig
以及任何其他提供程序或属性。例如
@Path("/test")
public class TestResource {
@GET
public String get() { return "hello"; }
}
public class TestResourceTest extends JerseyTest {
@Override
public Application configure() {
ResourceConfig config = new ResourceConfig();
config.register(TestResource.class);
}
@Test
public void doTest() {
Response response = target("test").request().get();
assertEquals(200, response.getStatus());
assertEquals("hello", response.readEntity(String.class));
}
}
您应该访问提供的链接来了解更多信息,并查看更多的示例。
https://stackoverflow.com/questions/32005902
复制相似问题