回答
編輯:這種解決方案只能與新澤西州的1.x工作,因此是相當過時。
它是指http://geek.riffpie.com/unit-testing-restful-jersey-services-glued-together-with-spring/庫。
如果你使用Spring,你可以擴展AbstractSpringAwareJerseyTest代替JerseyTest,並注入任何你所需要的。
按照要求,的一小段代碼:
public class MyClassTest extends AbstractSpringAwareJerseyTest{
@Autowired
private LdapSetupAndTearDown ldapSetupAndTearDown;
@Before
public void setUp2() throws Exception {
ldapSetupAndTearDown.setUp();
}
@After
public void tearDown2() throws Exception {
ldapSetupAndTearDown.tearDown();
}
public MyClassTest() throws Exception {
super(new WebAppDescriptor.Builder()
.contextPath("JSONUserServiceTest")
.contextParam("contextConfigLocation",
"classpath:/ctx-config-test.xml,classpath:/ctx-core.xml, classpath:/ctx-jmx-test.xml, classpath:ctx-jersey.xml, classpath:ctx-ldap.xml, classpath:ctx-ldap-test.xml")
.servletClass(SpringServlet.class).contextListenerClass(ContextLoaderListener.class).build());
}
我想他指向:http://geek.riffpie.com/unit-testing-restful-jersey-services-glued-together-with-spring/雖然我沒有得到它的工作。 – 2013-01-24 11:09:15
沒錯,本教程將我引向這個解決方案,並且它工作正常。感謝精確度。 – 2013-01-24 12:00:23
您是否願意詳細說明如何將'@ Autowired' bean注入測試類(例如,您是否註釋了一些'@ RunWith')?你能在這裏通過你的測試課的簡單例子嗎? – 2013-01-25 08:05:43
- 1. 澤西島測試框架
- 2. 單元測試與澤西島休息測試框架和Mockito
- 3. 澤西島測試 - ExceptionMapper未被調用
- 4. 與澤西島灰熊單元測試例外
- 5. 澤西島
- 6. 澤西單元測試與註釋
- 7. 打印澤西JSON的單元測試
- 8. 澤西島部署
- 9. 澤西島和Struts2
- 10. 澤西島json代
- 11. RESTEasy或澤西島?
- 12. 使用MessageBodyReader與澤西島
- 13. 在澤西島調用SOAP
- 14. 內省澤西島資源模型澤西島2.x
- 15. 遷移澤西島2.22.1到澤西島2.22.2
- 16. 澤西島:在澤西島以外的地方重定向
- 17. Rihno-mocks單元測試
- 18. 使用$ httpbackend mocks和打印稿進行單元測試
- 19. JAXB和澤西島名單解析?
- 20. 製作favicon.ico與澤西島
- 21. 依賴注入澤西島
- 22. @POST在澤西島查看
- 23. 澤西島2替代ServletContextListener
- 24. 澤西島2.5不讀jaxb.properties
- 25. 保護REST澤西島
- 26. 與RMI集成澤西島
- 27. JSON ArrayList在澤西島
- 28. 澤西島內存泄漏?
- 29. 澤西島異常Java 1.8
- 30. 澤西島的NIO支持
新澤西對我一個新的。我認爲每個人都使用JUnit或TestNG。 – duffymo 2011-05-08 23:51:19
擴展JerseyTest允許您添加常規JUnit @Test註釋,但我不知道如何在Spring配置中使用jersey-spring注入模擬服務。有什麼想法嗎? – alecswan 2011-05-09 20:09:15
當真的只有靜態方法時,你真的需要注入mockito嗎? – Spoike 2011-05-12 06:58:17