Any call in my unit tests to either Debug.Write(line)
or Console.Write(Line)
simply gets skipped over while debugging and the output is never print
I get no output when my Test/Test Settings/Default Processor Architecture setting and the assemblies that my test project references are not the same. Otherwise Trace.Writeline() works fine.
In Visual Studio 2017, you can see the output from test explorer.
1) In your test method, Console.WriteLine("something");
2) Run the test.
3) In Test Explorer window, click the Passed Test Method.
4) And click the "Output" link.
And click "Output", you can see the result of Console.Writeline().
It depends on your test runner... for instance, I'm using xUnit, so in case that's what you are using, follow these instructions:
https://xunit.github.io/docs/capturing-output.html
This method groups your output with each specific unit test.
using Xunit;
using Xunit.Abstractions;
public class MyTestClass
{
private readonly ITestOutputHelper output;
public MyTestClass(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void MyTest()
{
var temp = "my class!";
output.WriteLine("This is output from {0}", temp);
}
}
There's another method listed in the link I provided for writing to your Output window, but I prefer the previous.