簡體   English   中英

球衣測試框架文檔不起作用

[英]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'
}

是的,您正在查看錯誤的文檔。 您正在尋找的文檔適用於Jersey2.x。 但是您正在使用Jersey1.x。 您可以查看1.x的文檔,但是那里沒有太多事情。 最好的辦法是查看源代碼測試的示例。 您還可以在此答案的底部看到另一個示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM