我所有的测试在 Nunit 中都被忽略

发布于 2024-07-17 21:11:46 字数 2266 浏览 5 评论 0原文

我写了一个 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

任何人都可以告诉我,我哪里出错了。 只是试图实现一个通用的测试模式。

I have written a 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

And a 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

Can anyone plz tell, where I am getting wrong. Just trying to implement a generalised Test Pattern.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

机场等船 2024-07-24 21:11:46

您的测试被忽略的原因是所有 TestFixture 类都必须是公共的。 如果您没有具体声明可见性级别,则 .NET 假定您的类应该仅在程序集中可见(Friend 又名 C# 中的 Internal)。 由于 NUnit GUI 不是程序集的一部分,因此它无法创建 TestFixture。 只需将行:更改

Class HomePageTests

为:

Public Class HomePageTests

即可。

The reason your tests are being ignored is that all TestFixture classes must be public. If you do not specifically state a level of visibility, then .NET assumes your class should only be visible within your assembly (Friend aka Internal in C#). Since the NUnit GUI is not part of your assembly, it cannot create your TestFixture. Simple change the line:

Class HomePageTests

to:

Public Class HomePageTests

and you'll be good to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文