测试控制器有意义吗 [英] Does it make sense to test controllers

查看:83
本文介绍了测试控制器有意义吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的MVC应用程序,该应用程序由View-> Controller-> Service-> Model组成.

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

我的控制器真的很瘦.他们所做的只是调用服务方法并填充ModelAndView. 对控制器进行单元测试以确保它们在完全模拟服务时确保在ModelAndView中设置必需的属性是否被认为是一种好习惯?

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?

推荐答案

在某些时候,即使测试控制器也无害-然后,您可以确保它们调用正确的服务方法,并传递(修改-如果需要的话)正确请求参数并返回正确的ModelAndView.

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.

这篇关于测试控制器有意义吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆