Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enable trace output in NUnit 3's Visual Studio adapter?

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

like image 211
UserControl Avatar asked Aug 03 '16 13:08

UserControl


People also ask

What is the use of NUnit test adapter?

The NUnit Test Adapter allows you to run NUnit tests inside Visual Studio. The current release, version 2-0, is designed to work with Studio 2012 (All updates), Visual Studio 2013 (All updates) and Visual Studio 2015 (tested with all pre-releases, checked April 2015).

How do I view test output in Visual Studio?

If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.


2 Answers

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.

like image 136
lokusking Avatar answered Sep 18 '22 15:09

lokusking


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

Option 2: In your startup, add a TextWriterTraceListener

like image 23
kevin Avatar answered Sep 20 '22 15:09

kevin