我想编写一个单元测试来确保我返回的 View 是正确的。
我的计划是编写一个测试,首先调用 Controller ,然后调用我计划测试的 ActionResult 方法
我以为我可以写一些类似的东西
Controller controller = new HomeController();
var actionresult = controller.Index();
Assert.False(actionresult.ToString(), String.Empty);
这将允许我解析测试值的操作结果。
但是我不能直接实例化
public ActionResult Index()
方法。我该怎么做呢?
最佳答案
MVCContrib中的测试助手会在这里帮助你。
ViewResult result = controller.Index().AssertViewRendered().ForView("Blah");
关于asp.net-mvc - 如何测试 ASP.Net MVC View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/969889/