Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not able to print output to console window while running xunit tests

Tags:

c#

xunit

public class test2InAnotherProject
{
    private readonly ITestOutputHelper output;

    public test2InAnotherProject(ITestOutputHelper output)
    {
        this.output = output;
    }
    int Diff(int a, int b)
    {
        return (a - b);
    }
    int Div(int a, int b)
    {
        return (b / a);
    }

    [Fact]
    public void Test2()
    {
        int a = 2, b = 4;

        output.WriteLine("Test1: Project 2 in old library");
        int c = Diff(a, b);
        Assert.Equal(c, (a - b));
        output.WriteLine("Test1: Asssert done Project 2 in old library");
    }

    [Fact]
    public void Test3()
    {
        int a = 2, b = 4;

        output.WriteLine("Test2: Project 2 in old library");
        int c = Div(a, b);
        Assert.Equal(c, (float)((b / a)));
        output.WriteLine("Test2: Assert done Project 2 in old library");
    }
}

trying to print those lines when test is run through command prompt by using the command

dotnet test --no-build

Tried Console.Writeline, after which i tried with Output.WriteLine. Even when i run from Visual Studio am not able to get those lines printed in output window.

like image 658
Joe Pauly Avatar asked Dec 17 '22 18:12

Joe Pauly


1 Answers

Indeed there is no output with Console.WriteLine. And the ITestOutputHelper output is not shown in the Output window. Instead, when you click on the test in the Test Explorer, then there is an Output link. Click on that link to see the output.

To show the test output on the command line, use dotnet test --logger "console;verbosity=detailed".

enter image description here

like image 88
drizzd Avatar answered Dec 24 '22 02:12

drizzd