Can we unit test View ('V') of MVC?

后端 未结 5 679
走了就别回头了
走了就别回头了 2021-01-12 05:17

Duplicate: Unit Testing the Views?

Is there any way to unit test View? I am sure that we can test Model & Controller but don\'t know

5条回答
  •  攒了一身酷
    2021-01-12 05:31

    I do not see the point of unit testing the views, since they don't contain much logic. You can however to some integration testing/UI testing using a tool like WatiN.

    Example of a test written in WatiN:

    [Test]
    public void SearchForWatiNOnGoogle()
    {
       using (IE ie = new IE("http://www.google.com"))
       {
          ie.TextField(Find.ByName("q")).TypeText("WatiN");
          ie.Button(Find.ByName("btnG")).Click();
    
          Assert.IsTrue(ie.ContainsText("WatiN"));
      }
    }
    

    You should not try to test everything using tool like this. Select some key functionality of the application, and write test for them.

提交回复
热议问题