【发布时间】:2013-07-17 00:34:29
【问题描述】:
在 playframework 2.1 中,是否可以测试一个动作以确保呈现的视图是我所期望的?
在 ASP.NET MVC 3 中,AssertViewRendered().ForView("view") 进行了准确的测试。我们可以在play 2.1中做到吗?怎么样?
我想要实现的非常基本的 MVC 3 示例:
// Given the action GetUsers that renders the view "Users", I would like to assert
// this view as the one I expect and no other.
public class UserController
{
public ActionResult Index() {
return View("Users");
}
}
[Test]
public void GetUsersRendersCorrectView()
{
// Setup
var userService = new Mock<UserService>();
var userController = new UserController(userService.Object);
// Excercise
var result = userController.GetUsers();
// Verify
result.AssertViewRendered().ForView("Users");
}
谢谢。
【问题讨论】:
标签: java unit-testing playframework-2.1