JUnit中的invoke

AAAAServlet.java:
protected void execute(HttpServletRequest req, HttpServletResponse res, DataSource ds) {************}

AAAAServlet.javaをテスト
Class<? extends Object> clazz = AAAAServlet.class;
Method method = clazz.getDeclaredMethod("execute", HttpServletRequest.class, HttpServletResponse.class, DataSource.class);
method.setAccessible(true);
MockRequest req = new MockRequest();
req.setParameter(key, value);
MockResponse res = new MockResponse();
method.invoke(new AAAAServlet(), req, res, ds);
assertEquals(actualValue, res.getDocument());

 

posted @ 2015-03-09 09:56  taobr  阅读(354)  评论(0编辑  收藏  举报