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
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.