views:

1150

answers:

3

In NUnit, I'm used to writing Trace statements in the test, and having them show up in the trace tab of the NUnit gui.

On a new project, I'm moving to the built in Unit Testing in Visual Studio Professional Addition, which I believe is an interface to mstest.exe.

Test Code:

<TestMethod()>
Public Sub TestPagesInheritFromBasePage()
    Dim webUI As Assembly = Assembly.GetAssembly(GetType(WebUI.BasePage))
    Dim badPages As New List(Of String)
    For Each t As Type In webUI.GetTypes()
        Debug.Write(t.Name + ", ")
        Trace.Write(t.Name + ", ")
        If t.BaseType Is GetType(System.Web.UI.Page) Then badPages.Add(t.Name)
    Next
    Debug.Flush()
    Trace.Flush()
    If badPages.Count > 0 Then
        Assert.Fail("{0}: do not inheriting from BasePage", String.Join(", ", badPages.ToArray()))
    End If
End Sub

I'm getting a failure, so I know the Debug.Write and Trace.Write lines are executing.

I've read through the MSDN docs on writing these tests, and I can view the trace output if executing at the command line, via:

mstest.exe /testcontainer:mydll.dll /detail:debugtrace

However, I can not find the trace output when executing the tests directly in visual studio. Is there another preferred method of outputting information during a unit test, or am I missing an option to see trace info in visual studio?

Answer: Both of the answers below (Console.Write and Debug.Write) worked, the results were in Test Results Detail (TestResult Pane at the bottom, right click on on Test Results and go to TestResultDetails). Also, I set Debug and Trace constants in project properties.

+2  A: 

Usually I use this method to print something in the output window of visual studio:

System.Diagnostics.Debug.WriteLine("Message");
Michael Alves
it's still not showing up in output. I have tried both running the test and debugging through the test. I am calling Debug.Flush(), and have the output window set to show the debug output. Any idea what I'm missing here?
Tim Hoolihan
got it now, thanks!
Tim Hoolihan
+3  A: 

Hi there.

Try using Console.WriteLine() instead. I use that in my unit tests and it works fine - it displays text in unit test result output window.

Cheers. Jas.

Jason Evans
this worked too, thanks!
Tim Hoolihan
A: 

To see the results double click on the test in the "Test Results" window (Accessed from the main menu item "Tests" >> window menu >> Test Results)

bnieland