[英]jersey test framework documentation doesn't work
試圖建立一個您好的球衣測試。 https://jersey.java.net/documentation/2.5.1/test-framework.html看起來很簡單,但是當覆蓋所記錄的configure方法時不起作用。
從文檔中
package api;
import static org.junit.Assert.assertEquals;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import org.junit.Test;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
public class JerseyTester extends JerseyTest {
@Path("hello")
public static class HelloResource {
@GET
public String getHello() {
return "Hello World!";
}
}
@Override
protected Application configure() {
return new ResourceConfig(HelloResource.class);
}
@Test
public void testHelloWorld() {
WebResource webResource = resource();
String responseMsg = webResource.path("helloworld").get(String.class);
assertEquals("Hello World", responseMsg);
}
}
問題是configure方法的覆蓋不起作用-我收到錯誤消息:“返回類型與JerseyTest.configure()不兼容”。 我還收到錯誤消息:“無法實例化ResourceConfig類型”-當文檔明確聲明要實例化它時,怎么辦?
這是如此基礎,我不知道為什么它不起作用。 我只是想對一個純色澤西球衣端點進行測試。
這是我的依賴項:
dependencies {
compile 'javax.ws.rs:jsr311-api:1.1.1'
compile 'com.sun.jersey:jersey-server:1.19'
compile 'com.sun.jersey:jersey-core:1.19'
compile 'com.sun.jersey:jersey-client:1.19'
compile 'com.sun.jersey:jersey-servlet:1.19'
compile 'com.sun.jersey:jersey-json:1.19'
compile 'com.yammer.metrics:metrics-core:2.2.0'
compile 'com.yammer.metrics:metrics-servlet:2.2.0'
compile 'com.yammer.metrics:metrics-jersey:2.2.0'
compile 'com.yammer.metrics:metrics-graphite:2.2.0'
compile 'log4j:log4j:1.2.16'
testCompile 'junit:junit-dep:4.10'
testCompile 'com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly2:1.19'
testCompile 'org.slf4j:slf4j-simple:1.6.1'
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.