以下是我的代码,我正在使用 Visual Studio 2008 中提供的测试项目
Public Class Calculator
Public Shared objCalculator As Calculator = Nothing
Private Sub New()
End Sub
Public Shared Function GetInstance() As Calculator
If objCalculator Is Nothing Then
objCalculator = New Calculator
End If
Return objCalculator
End Function
End Class
测试方法
'''<summary>
'''A test for GetInstance
'''</summary>
<TestMethod()> _
Public Sub GetInstanceTest()
Dim expected As Calculator = Nothing
Dim actual As Calculator
actual = Calculator.GetInstance
Assert.AreNotEqual(expected, actual)
Assert.Inconclusive("Verify the correctness of this test method.")
End Sub
我是否遵循正确的方法来测试 Singleton 类。我正在使用 Assert.AreNotEqual(expected, actual)这个,