开发者

Unit tests on the UI in MVC3

I have an MVC project and lots of TDD unit tests for testing the passing of data which all work fine. However, I am now going to add some tests for the GUI.

How would I go about 开发者_如何学Gotesting something such as the below:

If home/page1, pressing "next" submit should goto "/Page2".

I still dont quite understand how to do tests on UI based features.


If you want to test the actions of the controller you can do something like that (i'm assuming a lot of things in this test but I hope you get the essentials)

[Test]
public void Page1_Post_IfallDataOK_ShouldSaveAndReturnPage2()
{
  var controller = new HomeController(repository.Object); //repository is: Mock<IRepository>
  var result = controller.Page1(new MyModel() {MyValue = "test"});
  Assert.IsInstanceOfType(typeof(RedirectToRouteResult), result);
  var redirect = (RedirectToRouteResult)result;
  Assert.AreEqual("Page2", redirect.RouteValues["action"]);
  repository.Verify(x => x.Save(It.IsAny<MyModel>()), Times.Once());
}


http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html

and

http://blog.davidebbo.com/2011/06/unit-test-your-mvc-views-using-razor.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜