aspose file tools*
The moose likes Spring and the fly likes How to unit test @ModelAttribute in Spring MVC controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to unit test @ModelAttribute in Spring MVC controller" Watch "How to unit test @ModelAttribute in Spring MVC controller" New topic
Author

How to unit test @ModelAttribute in Spring MVC controller

Nitesh Patel
Ranch Hand

Joined: Mar 16, 2008
Posts: 33
Hi All,
I am trying to develop unit test for below Spring MVC controller's method using Junit but I could not figure out how can I unit test the @ModelAttribute. Can anyone please guide me ?


Regards,
Nitesh
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

How about in your unit test just doing



Now the BindingResult object is a different matter. You have to instantiate one or create a mock of one. BindingResult is an interface, and there are implementations. Here is the Javadoc for it
http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/validation/BindingResult.html

Good Luck

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Nitesh Patel
Ranch Hand

Joined: Mar 16, 2008
Posts: 33
Thanks Mark,


Regards,
Nitesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to unit test @ModelAttribute in Spring MVC controller