title: How can I write unit test to test a ASP.NET MVC controller with the following code snippet
body: <p>All of these views don't even have a title. So I cannot do an </p>
  
  <blockquote>
    <p>Assert.AreEqual("Error",Viewbag.Title);</p>
  </blockquote>
  
  <p>How else can I test an error controller to ensure <strong>atleast</strong> <strong>85%</strong> code is covered</p>
  
  <pre><code>public class ErrorController : Controller
  {
      public ActionResult Index()
      {
          return View();
      }
  
      public ActionResult NotFound()
      {
          return View();
      }
      public ActionResult BadRequest()
      {
          return View();
      }
  
      public ActionResult ServerError()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>The best I could come up with was </p>
  
  <pre><code>public class ErrorControllerTests : BaseTestController
  {
      ErrorController ec = new ErrorController();
      [TestMethod()]
      public void IndexTest()
      {
          var actionResult = ec.Index() as ViewResult;
  
          Assert.AreSame(ec.ViewData, actionResult.ViewData);
          Assert.AreSame(ec.TempData, actionResult.TempData);
  
          Assert.AreEqual(actionResult.ViewName,"");
      }
  
      [TestMethod()]
      public void NotFoundTest()
      {
          var NotFoundTestResult = ec.NotFound() as ViewResult;
          Assert.AreEqual(NotFoundTestResult.ViewName,"");
      }
  
      [TestMethod()]
      public void BadRequestTest()
      {
          var badRequestTestResult = ec.BadRequest() as ViewResult;
          Assert.AreEqual(badRequestTestResult.ViewName,"");
      }
  
      [TestMethod()]
      public void ServerErrorTest()
      {
          var serverErrorTestResult = ec.ServerError() as ViewResult;
          Assert.AreEqual(serverErrorTestResult.ViewName, "");
      }
  }
  </code></pre>