Here is the unit test:
[TestFixture]
public class HomeControllerTests
{
[Test]
public void Index_GET_Asks_For_Index_View()
{
HomeController controller = new HomeController();
ViewResult result = controller.Index();
Assert.AreEqual("Index", result.ViewName);
}
}
Basically I want to make sure when I visit the Index action method that I invoke the correct view. However, the test fails and I don’t know why.
—— Test started: Assembly: Demo.Tests.dll ——
Test
‘Demo.Tests.HomeControllerTests.Index_GET_Asks_For_Index_View’
failed:Expected string length 5 but was 0. Strings differ at index 0.
Expected: “Index”
But was: ———–^ HomeControllerTests.cs(19,0): at
Demo.Tests.HomeControllerTests.Index_GET_Asks_For_Index_View()
Here is the actual controller code:
public ViewResult Index()
{
ViewBag.Message = "This is just a demo.";
return View();
}
See this reference with an empty call to View(). Here is a quote from that MSDN article: