如何在VB中编写NUnit自定义约束

时间:2017-05-25 13:59:48

标签: vb.net unit-testing nunit

我编码,成功编译并测试了NUnit自定义约束。

今天我回到VB项目来检查约束,以确保它能达到我想要的效果,现在Visual Studio会给出错误:

  

错误BC30610 Class' SPCG_LIB_NUnit_Constraint_ExceptionAndMessage'   必须声明' MustInherit'或覆盖以下内容   继承' MustOverride'构件(S):       约束:公共MustOverride重载函数ApplyTo(Of TActual)(实际为TActual)As   ConstraintResult。 SPCG_LibraryNUnit C:\ Development \ SPCG_LibraryNUnit \ SPCG_LibraryNUnit \ SPCG_LIB_NUnit_Constraint_ExceptionAndMessage.vb 14 Active

为了清晰起见,此处删除了ApplyTo实际内容的代码。

Public Class SPCG_LIB_NUnit_Constraint_ExceptionAndMessage
    Inherits Constraint

    Private m_Actual As Exception

    Private m_ExceptionObj As Exception

    Private m_Message As String

    Public Sub New(Exception As Exception)

        If Exception Is Nothing Then
            Throw New ArgumentNullException("Exception")
        End If

        m_ExceptionObj = Exception
    End Sub

    Public Overloads Function ApplyTo(Of TActual)(Actual As TActual) As ConstraintResult
        Dim ResultObj As ConstraintResult

        ResultObj = New ConstraintResult(Me, Actual, False)

        Return ResultObj

    End Function

End Class

NUnit 3.6.1

有人可以举例说明如何覆盖ApplyTo吗?

OverridesOverloads等的每个组合都会给我一些错误。

此外,我尝试删除代码然后键入Inherits Constraint语句,假设VS会自动为ApplyTo生成正确的语法。不。 VB列出了自动生成的ApplyTo的错误。

0 个答案:

没有答案