开发者

.net unit testing - How to do UI unit testing

I am using .net unit testing in my project. I would like to know if unit testing is required for UI part of the project or is it required for testing onl开发者_C百科y class libraries.

If UI unit testing is needed how can i test a functionality like enter some text in a textbox and write those content to the webpage on the click of a button.

Thanks in advance.


VS 2010 Premium and Ultimate ship with Coded UI tests which do UI testing


I think the usual plan is to put as little code in the UI as possible, putting everything into classes and unit testing them.

Possibly creating a class that shadows the UI and actually provides the actions that occur on button clicks etc will help you unit test as much functionality as possible.


It's User Interface. You as a user can unit test every bit after running your project.

Firebug and Tamper Data are great tools that help you do that.


I would look at a web automation tool such as Watin or selenium to automate the browser.

With Watin you can use .net to programatically find the elements on the page, Selenium you can record and replay.

Watin example

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

    Assert.IsTrue(browser.ContainsText("WatiN"));
  }
}


I have had success with unit testing my Javascript with QUnit and picking up the results of those tests with a single MSTest Unit test that uses WatiN.


With Visual Studio 2010 you can create coded UI Tests and you can also configure a Build agent to execute these tests: http://codesmartnothard.com/ConfiguringATFS2010TeamBuildServerToRunCodedUITests.aspx

this is exactly what you were asking, means you have a user interface and you can specify what should happen and in which controls, if user enters some data and clicks some buttons...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜