Does it make sense to test controllers

2019-06-22 06:24发布

问题:

I have a simple MVC application consisting of View->Controller->Service->Model.

My controllers are really skinny. All they do is call service method and populate the ModelAndView. Is it considered a good practice to unit tests controllers to make sure they set required properties in the ModelAndView while mocking the services completely?

回答1:

At some point it would not harm to test even controllers - then you would be sure that they are calling correct service methods, passing (modifying - if any needed) request parameters properly and returning correct ModelAndView.