I'm working on unit testing on asp.net mvc3. When I run the test method on a defaultly created test:
[TestMethod()]
public void IndexTest()
{
ConferenceController target = new ConferenceController()开发者_高级运维; // TODO: Initialize to an appropriate value
ActionResult expected = Index; // TODO: Initialize to an appropriate value
ActionResult actual;
actual = target.Index();
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
This error occurs [TestMethod()]
:
Assert.AreEqual failed. Expected:<(null)>. Actual:.
How to pass the assert?
ActionResult expected = Index; // TODO: Initialize to an appropriate value
As the comment indicates you should initialize the Index
variable to an appropriate value. Example:
[TestMethod]
public void Index()
{
// Arrange
HomeController controller = new HomeController();
// Act
ViewResult result = controller.Index() as ViewResult;
// Assert
Assert.AreEqual("Welcome to ASP.NET MVC!", result.ViewBag.Message);
}
精彩评论