I am writing unit tests to test MVC 3 controllers. I want to make sure that the view that is returned from the controller is the correct view. In my unit test, I have:
[Test]
public void It_Should_Return_The_Right_Page()
{
FormController fc = this.CreateFormController();
var view = fc.FindX();
Assert.AreEqual("FindX", view.ViewName);
}
In my controller, I have:
public ViewResult FindX()
{
return View();
}
This does not work because ViewName is null. If I change the call to say return View("FindX")and explicitly define the return view, it works. However, I would like to avoid this if possible. Is there a generally accepted way to approach this?
source
share