我想使用MvcContrib測試助手來測試MVC3中的控制器方法。MvcContrib TestHelper使用AssertViewRendered時出現奇怪的錯誤
控制器:
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.
任何想法?
剛試過用MVC2項目一樣,所有工作 – Ali 2010-12-10 15:23:07
@阿里:那你打算怎麼做?回到MVC 2?我也下載了MVC 3 RC 2,並且遇到了同樣的錯誤。 MVC contrib與MVC 3兼容嗎? – 2010-12-11 10:47:13
不確定是否誠實。這是一個個人項目,我正在嘗試使用TDD方法。現在我只是不打算使用MVC contrib測試助手。 – Ali 2010-12-13 11:21:22