运行 xunit 测试时无法将输出打印到控制台窗口 [英] not able to print output to console window while running xunit tests

查看:60
本文介绍了运行 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 测试 --no-build

dotnet test --no-build

尝试了 Console.Writeline,之后我尝试了 Output.WriteLine.即使我从 Visual Studio 运行,也无法在输出窗口中打印这些行.

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.

推荐答案

Console.WriteLine 确实没有输出.并且 ITestOutputHelper 输出不会显示在 Output 窗口中.相反,当您在 Test Explorer 中单击测试时,会出现一个 Output 链接.单击该链接以查看输出.

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.

要在命令行上显示测试输出,请使用 dotnet test --logger "console;verbosity=detailed".

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

这篇关于运行 xunit 测试时无法将输出打印到控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆