Dropwizard/Jersey - 运行测试时缺少公共方法的依赖项

She*_*jie 6 jersey dropwizard

我在使用Dropwizard运行resourceTest时遇到了"Missing dependency"异常:0.6.1(jersey 1.15),有没有人有这种情况的经验?

我的测试文件:

public class MyResourceImplTest extends ResourceTest {
   ........
    @Override
    protected void setUpResources() throws Exception {
        addResource(new MyResourceImpl(new myConfiguration()));
    }
}
Run Code Online (Sandbox Code Playgroud)

例外:

Dec 13, 2012 2:10:41 PM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer <init>
INFO: Creating low level InMemory test container configured at the base URI http://localhost:9998/
Dec 13, 2012 2:10:42 PM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer start
INFO: Starting low level InMemory test container
Dec 13, 2012 2:10:42 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.15 10/30/2012 02:40 PM'
Dec 13, 2012 2:10:42 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public javax.ws.rs.core.StreamingOutput com.****************.********(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String) at parameter at index 0
Dec 13, 2012 2:10:42 PM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer stop
INFO: Stopping low level InMemory test container
Run Code Online (Sandbox Code Playgroud)

She*_*jie 2

我的问题是,我注入了 InMemory 容器支持的 HttpServletRequest,在这种情况下我需要使用 jetty grizzlyWebTestContainer 或 jetty 作为测试容器。我也没有完全做到这一点,因为引入 jersey-test-framework-grizzly 确实给 dropwizard 本身带来了很多依赖冲突。我认为尝试解决所有冲突是不值得的,因为当我将来升级 dropwizard 时,这种情况可能会再次发生。

最终,我最终找到了一份 jenkins 工作,其中包含一些集成测试(Python)来测试我的 Web 服务。例如。部署后,触发一些http请求,检查响应代码和响应内容。事实证明要容易得多。