调试测试时跳过TestFixtureSetup

时间:2012-05-09 17:43:24

标签: vb.net nunit visual-studio-debugging

如果我尝试使用 Test With - >调试以下代码VS2010中的调试器选项,它在_object.DoSomething()上出现Object reference not set to an instance of an object.错误。它在NUnit中成功构建并传递。

<TestFixture()>
Public Class Tests

    Private _object As SomeClass

    <TestFixtureSetUp()>
    Public Sub TestFixtureSetup()
        _object = New SomeClass()
    End Sub

    <Test()>
    Public Sub Test()
        _object.DoSomething()
    End Sub

End Class

我调试时似乎跳过了<TestFixtureSetUp()>。为了解决方法,我修改了Test -

<Test()>
Public Sub Test()
    If Debugger.IsAttached Then
        TestFixtureSetup()
    End If          
   _object.DoSomething()
End Sub

但我是否需要这样做,或者在设计调试时跳过TestFixtureSetup

1 个答案:

答案 0 :(得分:0)

可能是命名惯例

尝试:

<TestFixtureSetUp()>
Public Sub SetUp()
    _object = New SomeClass()
End Sub