开发者

Assert.AreEqual failed. Expected:<(null)>. Actual:<System.Web.Mvc.ViewResult>

开发者 https://www.devze.com 2023-02-27 02:03 出处:网络
I\'m working on unit testing on asp.net mvc3. When I run the test method on a defaultly created test:

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消