我写了一个HomePageClass

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


谁能告诉我我哪里错了。只是尝试实现通用的测试模式。

最佳答案

您的测试被忽略的原因是所有TestFixture类都必须是公共的。如果您未特别指定可见性级别,则.NET假定您的类仅应在程序集中可见(C#中的Friend aka Internal)。由于NUnit GUI不是您的程序集的一部分,因此它无法创建TestFixture。简单更改行:

Class HomePageTests


至:

Public Class HomePageTests


这样您就很好了。

关于design-patterns - 我所有的测试都在Nunit中被忽略,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/776758/

10-12 03:21