我已经使用 guice-servlet 配置了我的 servlet/过滤器。使用类似的绑定
serve("/foo").with(HelloServlet.class);
现在,我想测试该映射。我用过码头测试
private ServletTester tester;
private HttpTester request;
private HttpTester response;
@BeforeMethod
public void setUp() {
this.tester = new ServletTester();
this.tester.setContextPath("/");
this.tester.addEventListener(new Config()); //my guice servlet config goes there.
this.tester.addFilter(GuiceFilter.class, "/*", 0);
this.tester.addServlet(FakeServlet.class, "/*"); <-----!!!!
this.tester.start();
this.request = new HttpTester();
this.response = new HttpTester();
this.request.setMethod("GET");
this.request.setHeader("Host", "tester");
this.request.setVersion("HTTP/1.0");
}
@Test
public void test() {
this.request.setURI("/foo");
this.response.parse(tester.getResponses(request.generate()));
assertEquals(this.response.getContent(), "Hello World");
}
有用。但这让我添加了一些应该被调用的假 servlet。如何在不添加此类 servlet 的情况下对其进行测试?