How to unit test a View in MVC 5?

All examples of MVC unit testing that I have seen relate to testing the controllers and whether they return expected views/results.

My Question: Is it possible to unit test a View in MVC 5, and if yes, then how would one go about doing this?

unit testing a view is checking that the correct html is produced for a given model. you normally would use an html parser to parse and validate the html. codeplex has a html parser for .net. see the razor generator on codeplex to be able to call a view
from a unit test.

if you plan on testing views a lot, I’d be tempted to have the unit test host node.js, and use its html parser, then you can use jquery/qunit to write the assert tests.  

Do you know of good links to examples of unit testing a view?

Leave a Reply