我有 Jersey Rest 资源,我想使用 Jersey 测试框架创建集成测试。我决定遵循这里的指南(https://jersey.java.net/documentation/latest/test-framework.html),因此我创建了以下集成测试
public class MyResourceIT extends JerseyTest {
public MyResourceIT() {
}
@Path("hello")
public static class HelloResource {
@GET
public String getHello() {
return "Hello World!";
}
}
@Override
protected Application configure() {
System.out.println("Configure was executed");
return new ResourceConfig(HelloResource.class);
}
@Test
public void testGetIt() {
System.out.println("getIt");
final String hello = target("hello").request().get(String.class);
assertEquals("Hello World!", hello);
}
}
Run Code Online (Sandbox Code Playgroud)
作为容器,我使用 Jetty 但问题是当我运行测试时出现以下错误:
-------------------------------------------------------------------------------
Test set: com.example.jerseywebapp.MyResourceIT
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.305 sec <<< FAILURE! - in com.example.jerseywebapp.MyResourceIT
testGetIt(com.example.jerseywebapp.MyResourceIT) Time elapsed: 0.169 sec <<< ERROR!
java.lang.NullPointerException: null
at org.glassfish.jersey.test.JerseyTest.target(JerseyTest.java:566)
at org.glassfish.jersey.test.JerseyTest.target(JerseyTest.java:580)
at com.example.jerseywebapp.MyResourceIT.testGetIt(MyResourceIT.java:68)
Run Code Online (Sandbox Code Playgroud)
有什么想法为什么会发生这种情况吗?
归档时间: |
|
查看次数: |
3218 次 |
最近记录: |