2011-11-16 78 views
2

我创建了一个类库prject运行在Visual Studio 2010中的单元测试,并作为Video Tutorial at Watin如何使用华廷

描述和使用下面的代码创建一个类:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using NUnit.Framework; 
using WatiN.Core; 

namespace ClassLibrary2 
{ 
[TestFixture] 
[RequiresSTA] 
public class Class1 
{ 
    [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")); 
     } 
    } 

} 
} 

现在下一步是什么,如何运行测试?我是否将类库添加到项目中并运行代码中的测试方法?或者我创建单元测试项目(如何?)?

感谢

+0

我在以前的线程中回答了这个问题... http://stackoverflow.com/questions/7685263/watinhow-to-use-the-automated-test-run-result-as-i-am-unable HTH! ! –

+0

谢谢你,所以你的意思是,我需要从一个控制台应用程序外部运行测试,什么样的?这是最好的方法吗? –

+0

究竟什么是你想怎么办? –

回答

1

要执行你的测试,你需要编译代码,然后通过测试运行器运行测试。

我做过这个是使用NUnit的GUI

  1. 编译代码的类库的第一种方式。结果是一个.dll文件;类似MyTests.dll
  2. 打开NUnit GUI。开始 - >程序 - >等等等等等
  3. 在NUnit GUI中,打开包含测试的.dll文件。
  4. 在NUnit的GUI,选择测试(S)你想运行并点击运行按钮。

有很多其他的方式来运行测试,但我相信NUnit的GUI是最基本的NUnit的测试。其他选项包括:在Visual Studio中通过ReSharper,Gallio,在VS中通过外部工具等等。