单元测试大型控制器动作 [英] Unit Testing large controller actions

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

问题描述

I've a web page that has many constituent parts.

根据某些用户操作,将执行POST操作,然后返回JSON以更新页面.问题在于,此JSON有效负载包含许多根据许多不同的操作和类构建的信息.然后使用JSON数据更新许多 通过Ajax回调获得部分视图.

On some user action, a POST operation is made, which then returns JSON to update the page. The problem is that this JSON payload contains a lot of information built from many different operations and classes. The JSON data is used then to update a number of partial views via the Ajax callback.

我的问题是,对此进行单元测试的最佳方法是什么?这个动作方法是否应该甚至负责整理所有这些信息并返回一个块,还是应该通过对网页上不同动作的多个Html调用来完成? 我认为这更容易进行单元测试.

My question is, what is the best way of unit testing this? Should this one action method even be responsible for collating all this information and returning in one chunk, or should it be done via a number of Html calls to different actions from the web page? That would I think be easier to unit test.

目前,我可能针对一个动作编写8个测试,而我通常不得不模拟一些测试不需要的操作.

Currently I may write 8 tests against a single action which I generally have to mock a number of operations which are not needed for some tests.

推荐答案

就像您提到的标题一样,您的案例与单元测试有关,因此,我将把您的主题移至单元测试论坛以获得更好的支持.

Like your title mentioned, your case related to Unit Testing, So i will move your thread to Unit test forum for better support. 

度过愉快的一天!

kristin


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

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