2009-04-22 55 views
2

被忽略,我已經寫了HomePageClass我所有的測試在NUnit的

Imports System 
Imports System.Collections.Generic 
Imports System.Text.RegularExpressions 
Imports System.Text 
Imports WatiN.Core 

Namespace TestDesign 
    Public Class HomePage 
     Inherits IE 
     Public Const HomePageURL As String = "test" 

     Public Sub New() 
      MyBase.New(HomePageURL) 
     End Sub 

     Public Sub New(ByVal instance As IE) 
      MyBase.New(instance.InternetExplorer) 
     End Sub 

     Public ReadOnly Property UserIDField() As TextField 
      Get 
       Return TextField(Find.ById(New Regex("txtuserName"))) 
      End Get 
     End Property 

     Public ReadOnly Property PasswordField() As TextField 
      Get 
       Return TextField(Find.ById(New Regex("txtPassword"))) 
      End Get 
     End Property 

     Public ReadOnly Property ContinueButton() As Button 
      Get 
       Return Button(Find.ById(New Regex("Submit"))) 
      End Get 
     End Property 

     Public ReadOnly Property UserRegistrationLink() As Link 
      Get 
       Return Link(Find.ByUrl("userregistration.aspx")) 
      End Get 
     End Property 

     Friend Sub Login(ByVal username As String, ByVal password As String) 
      UserIDField.TypeText(username) 
      PasswordField.TypeText(password) 
      ContinueButton.Click() 
     End Sub 

     'Friend Function GoToUserRegistration() As UserRegistrationPage 
     ' UserRegistrationLink.Click() 
     ' Return New UserRegistrationPage(Me) 
     'End Function 
    End Class 
End Namespace 

而一個HomePagetestsClass

Imports System.Threading 
Imports NUnit.Framework 
Namespace TestDesign 

<TestFixture()>_ 
Class HomePageTests 

    <Test()> _ 
    Public Sub GoToHomePageTest() 
     Dim home As New HomePage() 
     Assert.IsTrue(home.ContainsText("Welcome")) 
     home.Close() 
    End Sub 

    <Test()> _ 
    Public Sub Login() 
     Dim home As New HomePage() 
     home.Login("abc", "def") 
     Assert.IsTrue(home.ContainsText("Welcome")) 
     home.Close() 
    End Sub 
End Class 

誰能告訴PLZ,在那裏我得到錯誤的。試圖實現一個廣義的測試模式。

回答

6

您的測試被忽略的原因是所有的TestFixture類都必須是公共的。如果你沒有具體說明一個可見性級別,那麼.NET假定你的類只能在你的程序集中可見(在C#中的朋友又名爲Internal)。由於NUnit GUI不是你的程序集的一部分,它不能創建你的TestFixture。簡單更改的行:

Class HomePageTests 

到:

Public Class HomePageTests 

,你會好到哪裏去。

+0

謝謝。是的現在工作正常。通過公開 – sam 2009-04-22 12:04:41