18

Consider:

[Test]
public void Test1()
{
    Trace.TraceInformation("Hello");
}

When running it from Visual Studio 2015, the output window (Tests) shows no trace lines:

------ Discover test started ------
NUnit Adapter 3.4.0.0: Test discovery starting
NUnit Adapter 3.4.0.0: Test discovery complete
========== Discover test finished: 9 found (0:00:01.325888) ==========
------ Run test started ------
NUnit Adapter 3.4.0.0: Test execution started
Running selected tests in C:\Projects\bla-bla.dll
NUnit3TestExecutor converted 9 of 9 NUnit test cases
NUnit Adapter 3.4.0.0: Test execution complete
========== Run test finished: 1 run (0:00:03.5445181) ==========

I remember it was working fine with NUnit 2 and Visual Studio 2013. Do I need to somehow turn it on?

My app.config has no overrides to default <system.diagnostics>.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
UserControl
  • 14,766
  • 20
  • 100
  • 187

2 Answers2

16

According to this discussion, they removed that because of technical reasons.

An alternative solution might be something like this:

using NUnit.Framework;

    namespace MyUnitTest {
        [TestFixture]
        public class UnitTest1 {
            [Test()]
            public void Test1() {
                var x = "Before Test";
                TestContext.Progress.WriteLine(x);
                x = "Hello";
                TestContext.Progress.WriteLine(x);
                Assert.IsTrue(x == "Hello");
                x = "After Test";
                TestContext.Progress.WriteLine(x);
            }
        }
    }

With the given result:

NUnit Adapter 3.4.1.0: Test execution started Running selected tests in C:\ProjectPath\MyUnitTest.dll NUnit3TestExecutor converted 1 of 1
NUnit test cases Before Test Hello After Test NUnit Adapter 3.4.1.0:
Test execution complete
========== Test execution complete: 1 run(0:00:00,7660762) ==========

Conclusion

You can't use Trace anymore on outputs for NUnit.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lokusking
  • 7,396
  • 13
  • 38
  • 57
  • Is this line normal - "NUnit3TestExecutor converted 9 of 9 NUnit test cases"? It sort of looks like it is doing extra work every time, why are they "converted"? – Alex Strickland Aug 16 '16 at 11:18
  • I think that's because NUnit and VS test interfaces are different so NUnit VS adapter has to "convert" its tests so that VS understands them. – UserControl Aug 16 '16 at 15:55
  • "You cant use Trace anymore on outputs for NUnit" well it is possible to register a listener and redirect the information to whatever sink – max630 Dec 11 '19 at 11:09
1

Option 1: You can use the output window to review trace information

Option 2: In your startup, add a TextWriterTraceListener

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kevin
  • 338
  • 2
  • 13