Reputation: 29159
For example, there is a class to be tested.
public class ToBeTested
{
public static void Method1()
{
Debug.WriteLine("....for debugging....");
}
}
And It's invoked by xUnit test method
[Fact]
public void Test1()
{
ToBeTested.Method1();
}
However, the line Debug.WriteLine("....for debugging....");
didn't write anything in Visual Studio debug output?
Upvotes: 1
Views: 356
Reputation: 164
The line Debug.WriteLine("....for debugging....");
will write the output to the Debug Output window of visual studio only when the tests are ran in Debug mode. Instead of "Run Tests" you can use "Debug Tests" and can see the output in window.
But if you are trying to output results while running XUnit tests, then it is better to use ITestOutputHelper
in namespace Xunit.Abstractions
.
Code sample is available in : https://xunit.github.io/docs/capturing-output.html
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);
}
}
Upvotes: 1