Asp.net mvc 3 Assert.AreEqual失败。预期:<;(空)>;。实际:<;System.Web.Mvc.ViewResult>;
我正在asp.net mvc3上进行单元测试。在默认创建的测试上运行测试方法时:Asp.net mvc 3 Assert.AreEqual失败。预期:<;(空)>;。实际:<;System.Web.Mvc.ViewResult>;,asp.net-mvc-3,Asp.net Mvc 3,我正在asp.net mvc3上进行单元测试。在默认创建的测试上运行测试方法时: [TestMethod()] public void IndexTest() { ConferenceController target = new ConferenceController(); // TODO: Initialize to an appropriate value ActionResult expected = In
[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.");
}
出现此错误[TestMethod()]
:
Assert.AreEqual失败。预期:。实际值:
如何传递断言
ActionResult expected = Index; // TODO: Initialize to an appropriate value
如注释所示,您应该将索引
变量初始化为适当的值。例如:
[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);
}
只需阅读单元测试方法的摘要,上面给出的解决方案不起作用///////索引测试/////TODO:确保UrlToTest属性指定指向ASP.NET页面的URL(例如,///http://.../Default.aspx). 这是在web服务器上执行单元测试所必需的,//无论您是在测试页面、web服务还是WCF服务。实施上述错误后,现在出现了。。。。。。。????????????