locked
Unit Testing large controller actions RRS feed

  • Question

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

    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.

    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.

    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.

    • Moved by Kristin Xie Wednesday, January 7, 2015 6:05 AM
    Tuesday, January 6, 2015 9:13 AM

All replies

  • Hi,

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

    Have a ncie day!

    kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 7, 2015 6:02 AM
  • Hi TechEliteBattlefield,

    This blog share us some different ways to test the JSON, if possible, please refer to them:

    Unit Testing The MVC JsonResult

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 8, 2015 3:40 AM