我正在尝试使用MvcContrib Test Helper来测试MVC3中的控制器方法.
控制器:
public class HomeController : Controller { public ActionResult Index() { return View(); } }
考试:
[TestMethod] public void Index() { // Arrange HomeController controller = new HomeController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert result.AssertViewRendered().ForView("Index"); }
错误:
Test method Tests.Web.Controllers.HomeControllerTests.Index threw exception:
MvcContrib.TestHelper.ActionResultAssertionException:
Expected result to be of type ViewResult. It is actually of type ViewResult.
有任何想法吗?
解决方法
我的猜测是你正在使用MVCC的MVCC2,它使用MVC2 ViewResult.然而,你正在返回一个MVC3 ViewResult.
您是否尝试过针对MVC3编译MVCContrib?