Testing ASP.Net MVC 4 Application Components

I understand that this is a duplicate of about 20 different posts, but not one of them is specific to MVC4, and not one of them that I saw really answers all my questions. So far, my first foray into the TDD world has been, at the very least, disappointing. Most of what I tried to do seems incompatible with MVC 4 or next to impossible without using poorly documented third-party libraries, which I still don't quite understand.

What I want to do is write tests that will validate my actions with the controller, the model that they pass, and the "Show action" view sends the model. I want to check if a view exists, I want to check if the model is the right type for the view, I would like to somehow check if it will be processed properly. I also want to check my routes. And testing authentication filters?

I need a unit test method ASP.Net MVC that leaves very little chance.

Testing the output of the Action model is simple enough, but checking the views was almost impossible.

So here is my list of questions:

  • Once I test the action and get the result of the action, how can I check if the view that it wants exists?
  • How to check my routes?
  • How can I check if my views are being processed correctly?
  • What is the "best practice" for unit testing THOROUGH ASP.Net MVC 4?
  • How to do unit test form authentication?
  • How to make unit test Action Filters?

I would prefer to use Visual Studio's built-in test projects, but if I have to use NUnit, I have to. I just need to make sure that this is done correctly.

Thanks in advance for your answers.

EDIT: I also could not get NUnit to work with my MVC4 application due to incompatibility with the .NET version. One of the collections was compiled.

+60
unit-testing tdd visual-studio visual-studio-2010 asp.net-mvc-4
Feb 10 2018-12-12T00
source share
1 answer

no. 4: This is a difficult question. How to check something completely? Personally, I actually do not test my views, except for the three main browsers and my two eyes, since it is difficult to test the website and all its components without actually using it. You have JavaScript firing, CSS styling, and it looks different in different browsers. So, for me, this is like checking the look, which is a secondary part of the overall usability of your site. If you are developing a simple table-based financial data report, check that data carefully. If your presentation is the basis for a fancy Ajax site, maybe don't test the HTML as much as experience. I know this is not an easy answer, but an acceptable level of coverage is always associated with a compromise.

+59
Mar 29 '12 at 0:10
source share



All Articles