Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I'm trying to test the Public interface of Class1, and somehow view the output from the Class1.PrintToDebug() function.

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.

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

Thanks for your help!


Edit: I'm using VB.Net 2.0, TestDriven.Net 2.14.2190 and NUnit 2.4.8.0
like image 760
Andrew Avatar asked Oct 06 '08 09:10

Andrew


People also ask

Where can I find debug WriteLine?

Debug. WriteLine will display in the output window ( Ctrl + Alt + O ), you can also add a TraceListener to the Debug. Listeners collection to specify Debug.

How do I view the Console WriteLine in Visual Studio 2022?

In Visual Studio uppermost menu choose Debug > Windows > Output. It shows all Console.

Where does debug print Go C#?

Use Debug. WriteLine to write debug output. The output will be displayed in your IDE. Assuming Visual Studio, it will write to the Output window when you run the project.

What is debug WriteLine?

WriteLine(String) Writes a message followed by a line terminator to the trace listeners in the Listeners collection. WriteLine(Object) Writes the value of the object's ToString() method to the trace listeners in the Listeners collection.


2 Answers

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

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.

like image 185
Jon Limjap Avatar answered Oct 10 '22 00:10

Jon Limjap


Trace.WriteLine() appears to be the answer :o)

Here's the output for the example from my question, using Trace instead of Debug:

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

Internal state of Class1: True

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

One thing I've found though.. execution is halted at the first failing unit test assertion, meaning that Trace statements aren't executed if an Assert() above them fails.

like image 29
Andrew Avatar answered Oct 10 '22 00:10

Andrew