How can I see Debug.WriteLine statements when using TestDriven.Net?

I am trying to use TestDriven.Net not only to test my code, but also to call a function in my code whose purpose is to print the internal state of the code in a debug window.

Here is 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

I am trying to check the open interface of Class1 and somehow view the output from the function Class1.PrintToDebug().

I looked at TestDriven.Net quickstart , which shows examples of use Debug.WriteLinein unit test, but strangely this also does not work for me - that is, the only way out in my "Test" window:

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


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

I tried to look in other windows (Debug and Build), the Debug window has the options "Program Exit" and "Exceptional Messages".

I searched for options or settings and cannot find them!

Thank you for your help!


Edit: I am using VB.Net 2.0, TestDriven.Net 2.14.2190 and NUnit 2.4.8.0
+5
source share
7 answers

I found that although Debug.Writeline () does not work with unit tests, Console.WriteLine () does.

The reason is that when you run tests, the debugger process is not called, and Debug.WriteLine () is ignored. However, if you use "Test with Debugger", I think (have not tried) Debug.WriteLine () will work.

+10
source

Trace.WriteLine() represented by the answer: o)

Here's the output for an example from my question, using Traceinstead Debug:

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

Internal state of Class1: True

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

, , .. unit test, , Trace , Assert() .

+2

Trace.WriteLine(...). Debug.WriteLine(...) DEBUG. Visual Studio DEBUG, TRACE.

quickstart, Trace .

, .

+2

, , 2.16 ( -) :

1587: /

/.

1588: / /

/ /. TesDriven.Net .

, , .

+1

IIRC, . , ...?

0

"Run Tests ..." selects all the settings that you currently need to build for your solution / project.

You must make sure that the current build settings for your solution / project are set to "Debug" and not "Release" (otherwise the calls to Debug.Write * () are conditionally deleted by the compiler).

0
source

CTRL + ALT + I show the closest window

0
source

All Articles