我怎么看的Debug.WriteLine语句中使用TestDriven.Net什么时候?什么时候、怎么看、语句、Debug

2023-09-05 23:45:44 作者:失去太阳

我试图用TestDriven.Net不仅考验我的code,但调用一个函数在我的code,其目的是打印出的code的内部状态调试窗口。

I'm trying to use TestDriven.Net not only to test my code, but to call a function on my code whose purpose is to print out the internal state of the code to the Debug window.

下面是什么,我试图做一个很简单的例子。

Here's a very simplified example of what I'm trying to do..

<TestFixture()> _
Public Class UnitTest

    <Test()> _
    Public Sub TestDebug()
        Dim oClass1 As New Class1

        Assert.AreEqual(True, oClass1.IsTrue)

        Debug.WriteLine("About to call .PrintDebug()")
        oClass1.PrintToDebug()

    End Sub

End Class

Public Class Class1

    Private _IsTrue As Boolean = True

    Public ReadOnly Property IsTrue() As Boolean
        Get
            Return _IsTrue
        End Get
    End Property

    Public Sub PrintToDebug()
        Debug.WriteLine("Internal state of Class1: " & _IsTrue)
    End Sub

End Class

我想要测试Class1的公共接口,并以某种方式查看从 Class1.PrintToDebug()函数的输出。

我通过 TestDriven.Net快速启动,其中显示了使用的例子看的Debug.WriteLine 在一个单元测试,但奇怪的是这并没有为我工作或者 - 即在我的测试窗口中的唯一输出是:

I've looked through the TestDriven.Net quickstart, which shows examples of using the Debug.WriteLine in a unit test, but strangely this doesn't work for me either - i.e. the only Output in my 'Test' window is:

------ Test started: Assembly: ClassLibrary1.dll ------


1 passed, 0 failed, 0 skipped, took 1.19 seconds.

我试图寻找在其他窗口(调试和生成),调试窗口中有程序输出和异常消息选项启用。

I've tried looking in the other windows (Debug and Build), the Debug window has the 'Program Output' and 'Exception Messages' options enabled.

我看的选项或preferences,找不到任何!

I've looked for options or preferences and can't find any!

感谢您的帮助!

修改我使用VB.Net 2.0,TestDriven.Net 2190年2月14日和NUnit 2.4.8.0

I'm using VB.Net 2.0, TestDriven.Net 2.14.2190 and NUnit 2.4.8.0

推荐答案

我发现,虽然的Debug.WriteLine()不与单元测试,Console.WriteLine工作()一样。

I found that while Debug.Writeline() doesn't work with unit tests, Console.WriteLine() does.

原因是,当你运行测试,调试过程中不会被调用,和的Debug.WriteLine()将被忽略。但是,如果使用测试与调试,我觉得(没试过)的Debug.WriteLine()将工作。

The reason is that when you run tests, the debugger process isn't invoked, and Debug.WriteLine() is ignored. However, if you use "Test with Debugger", I think (haven't tried) Debug.WriteLine() will work.