testing SpringMVC controllers
Posted
by Don
on Stack Overflow
See other posts from Stack Overflow
or by Don
Published on 2010-04-22T12:01:09Z
Indexed on
2010/04/22
12:03 UTC
Read the original article
Hit count: 466
spring-mvc
|validation
Hi,
I'm unit-testing my SpringMVC (v. 2.5) controllers using code like the following:
public void testParamValidation() {
MyController controller = new MyController();
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("foo", "bar");
request.addParameter("bar", baz");
ModelAndView mav = controller .handleRequest(request, new MockHttpServletResponse());
// Do some assertions on mav
}
This controller is a subclass of AbstractCommandController
, so the parameters are bound to a command bean, and any binding or validation errors are stored in an object that implements the Errors
interface.
I can't seem to find any way to access this Errors
from within the test, is this possible?
Thanks, Don
© Stack Overflow or respective owner