我应该对 DefaultModelBinder 返回的模型进行单元测试吗?
我在对 DefaultModelBinder 返回的模型进行单元测试时遇到一些麻烦。我想输入一个假表单集合并检查它返回的模型以确保模型属性正确绑定。在我的研究中,我没有提供任何用于测试 DefaultModelBinder 的资源。也许我错过了一些东西。也许我不应该测试 MVC 的这一部分?你的想法?
I'm having some trouble unit testing the model returned by DefaultModelBinder. I want to feed in a fake form collection and check the model that it returns to make sure model properties are being bound properly. In my research, I'm not turning up -any- resources on testing the DefaultModelBinder. Maybe I'm missing something. Maybe I shouldn't be testing this part of MVC? Your thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
拜伦,我真的认为你不应该测试这个。您必须关注控制器操作以及它们可能与其他组件(如服务等)的交互。默认的模型绑定器已经由 MS 团队测试过(我希望如此:P)。只需假设您的操作参数已通过默认模型绑定器正确填充了表单发布的值,并使用您自己构建的对象测试控制器中的操作。
这是我经常做的事情,也是我随处可见的事情。
问候。
Byron, I really think you shouldn't be testing this. You have to focus on your controller actions and the interactions they may have with other components, like services, etc. The default model binder has already been tested by the MS team (I hope so :P). Just assume your action parameters have correctly been populated with the form posted values by the default model binder and test the actions in your controllers with objects built by yourself.
This is what I usually do and what I have seen everywhere.
Regards.