关闭

单元测试工具及资源推荐

发表于:2009-5-20 11:59

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:网络转载

  三.NunitForms

  NUnitForms从 命名上看,就知道它跟NUnit有关,没错,它是NUnit的一个WinFrom的扩展。它为Windows Forms应用程序提供单元测试和压力测试,可以非常容易的用它为你的Windows Forms类进行自动化测试,它提供了一个Recorder Application,来记录你的操作。我们编写类似于如下代码片断的测试代码:

  ButtonTester button = new ButtonTester(\"buttonName\", \"formName\");

  ControlTester textBox = new ControlTester(\"nameOfSomeTextBox\");

  Assertion.AssertEquals(\"defaultText\", textBox[\"Text\"];

  textBox[\"text\"] = \"newText\"

  或者类似于这样的代码进行操作记录:

  //records button.Click() public void Click(object sender, EventArgs args){

  listener.FireEvent(TesterType, sender, \"Click\");

  }//records: comboBox.Enter(\"text\"); public void TextChanged(object sender, System.EventArgs e){

  listener.FireEvent(TesterType, sender, \"Enter\", ((ComboBox)sender).Text);

  }//records: comboBox.Select(3); //text of item 3 public void SelectedIndexChanged(object sender, System.EventArgs e){

  EventAction action = new EventAction(\"Select\", ((ComboBox)sender).SelectedIndex);

  action.Comment = ((ComboBox)sender).Text;

  listener.FireEvent(TesterType, sender, action);

  }

  对于NUnitForms,它还有一个兄弟工具叫NUnitASP,

  学习资源

  对于NUnitForms,仍然是没有发现有好的中文资源,大家可以参考官方文档。

  四.NUnitAsp

  NUnitAsp可以说是NUnitForms的兄弟,它也是一个NUnit的扩展,用来自动测试ASP.NET页面。虽然NunitAsp可以完成一些ASP.NET页面的自动化测试工作,但是在编写测试用例的时候,如果界面上的元素比较多,编写起来会非常的麻烦,这也是为什么NunitAsp一直处于大紫不红的原因。它可以编写如下代码片断的测试代码: [Page]

  public void TestLayout(){

  TextBoxTester name = new TextBoxTester(\"name\", CurrentWebForm);

  TextBoxTester comments = new TextBoxTester(\"comments\", CurrentWebForm);

  ButtonTester save = new ButtonTester(\"save\", CurrentWebForm);

  DataGridTester book = new DataGridTester(\"book\", CurrentWebForm);

  Browser.GetPage(\"http://localhost/GuestBook/GuestBook.aspx\");

  AssertVisibility(name, true);

  AssertVisibility(comments, true);

  AssertVisibility(save, true);

  AssertVisibility(book, false);

  }public void TestSave(){

  TextBoxTester name = new TextBoxTester(\"name\", CurrentWebForm);

  TextBoxTester comments = new TextBoxTester(\"comments\", CurrentWebForm);

  ButtonTester save = new ButtonTester(\"save\", CurrentWebForm);

  DataGridTester book = new DataGridTester(\"book\", CurrentWebForm);

  Browser.GetPage(\"http://localhost/GuestBook/GuestBook.aspx\");

  name.Text = \"Dr. Seuss\" comments.Text = \"One Guest, Two Guest! Guest Book, Best Book!\" save.Click();

  }

  学习资源

  跟自己的兄弟NUnitForms一样,仍然没有好的中文文档,有兴趣的朋友可以参考‘NUnitAsp的官方文档,相对来说还是比较全的,有很多的教程。

  总结

  对于单元测试工具,就简单的介绍这么多,我个人还是推荐使用TestDriven.Net的个人版,至于后面两个NUnit的扩展,大家可以参考一下,在实际开发中用它们来测试会很麻烦,至少我目前不敢去做这个尝试。还有一个非常值得推荐的单元测试工具Mbunit,有兴趣的朋友可以关注一下,我对它了解并不多。

  评论:

  页面测试,可以关注一下 watiN,他可控制到 dialog/frame/js的alert/confirm 的测试。

  http://watin.sourceforge.net/

  单元测试的部份,我们是用 NUnitLite。

  http://www.codeplex.com/NUnitLite

  功能少nunit很多-_-,但他可以测试 web site project 里app_code里的cs。

  符合工作的需求,也可参考看看。

  对于Mobile的单元测试工具,恐怕很难找,因为netcf对于反射支持有限,而像NUnit这样的工具也用到了反射。最典型的例子就是NDoc,这个对netcf有的时候就爱莫能助了。

  ReSharper UnitRun

  \"is a free add-in for Microsoft Visual Studio 2005 that allows you to automatically run and profile unit tests. This user-friendly tool detects test fixtures of the supported unit testing frameworks and lets you run or profile them right from the code editor or from Visual Studio\'s Solution Explorer. \"

  免费但不是开源的...

  http://www.jetbrains.com/unitrun/

  VS2007 将支持Mobile 系统的 unit test, 请大家关注。

  另外,VS2005 database professsional 版本已经发布,支持SQL的单元测试,请大家试用。

22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号