【问题标题】:TestFixtureSetup skipped when debugging tests调试测试时跳过了 TestFixtureSetup
【发布时间】:2012-05-09 17:43:23
【问题描述】:

如果我尝试使用 VS2010 中的 Test With -> Debugger 选项调试以下代码,它会在 _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

我调试时似乎正在跳过&lt;TestFixtureSetUp()&gt;。为了解决这个问题,我修改了Test -

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

但是我应该这样做还是在设计调试时跳过TestFixtureSetup

【问题讨论】:

  • 你有没有尝试过 intead off TestFixtureSetup
  • 还是一样的行为。在我看来,在调试测试时,通常的“测试”事件不会被触发。例如,如果我在
  • 使用“Test With -> Debugger”选项时,仅调试光标下的测试方法,并且不会触发预期的 NUnit“test”事件序列。例如,如果我在 中设置断点,然后对 进行调试,则 中的断点不会被激活。反之亦然。

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


【解决方案1】:

可能是命名约定

试试:

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

【讨论】:

  • 谢谢,但我仍然得到相同的行为。
猜你喜欢
  • 2011-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-03
  • 2021-04-30
  • 1970-01-01
  • 1970-01-01
  • 2014-01-04
相关资源
最近更新 更多