Here is an example from Professional ASP.NET MVC 1.0 (book):
[TestMethod] public void AboutReturnsAboutView() { HomeController controller = new HomeController(); ViewResult result = controller.About() as ViewResult; Assert.AreEqual("About", result.ViewName); }
Note that this will fail if you do not return the explicit view in your controller method, i.e. do the following:
Return(View("About"));
Not this:
Return(View());
Or the test fails. You will need to do this only if your method ever returns more than one view, otherwise you should return the implicit view in any case and not bother testing the framework.
source share