4
我有兩個問題:如何設置Servlet上下文澤西單元測試框架2.5
1)如何設置servlet上下文的延伸JerseyTest
單元測試。從我所做的研究中,似乎我必須創建一個TestContainer
TestFactory
並通過AppDescriptor
,但似乎更復雜,然後它應該是。那裏有其他建議嗎?
通常,尋找一種方法來設置我的Jersey資源類的單元測試中的Servlet上下文,這通常由web.xml完成。
實施例:
@Path(value = "/service")
public class Foo{
@Context ServletContext ctx;
@GET
@Path(value="/list")
public String list() {
Controller ctrl = new Controller();
ctx.setAttribute("controller", ctrl);
return ctrl.getList();
}
}
public class FooUnitTest extends JerseyTest
{
@Test
public void testService()
{
//set/how to configure the context?
}
}
的目標是模擬出的控制器,所以我可以將它傳遞到的上下文。
2)什麼是使用從
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly</artifactId>
<version>1.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
與
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-bundle</artifactId>
<version>2.4.1</version>
</dependency>
我也在學習這一點,所以請與我裸露的球衣測試之間的差異。這是Jersey框架2.5
任何意見讚賞, 感謝
不知道爲什麼點是零下關閉格式化。除非你有一個有效的解決方案 – darewreck