Output from xUnit tests run with Visual Studio test runner not shown in Output window

℡╲_俬逩灬. 提交于 2019-12-11 01:32:55

问题


I created a fresh .NET Core Class Library project named FooBarBaz. I've then used the package manager console to run:

  • Install-Package xunit xunit
  • Install-Package xunit xunit.runners.visualstudio

This is the only code I have added:

using Xunit;
using Xunit.Abstractions;

namespace FooBarBaz
{
    public class Class1
    {
        private readonly ITestOutputHelper output;

        public Class1(ITestOutputHelper output)
        {
            this.output = output;
            output.WriteLine("OUTPUT FROM MY CONSTRUCTOR");
        }

        [Fact]
        public void SmokeTest()
        {
            output.WriteLine("OUTPUT FROM MY TEST");
            Assert.True(true);
        }
    }
}

This is based straight on the xUnit.net documentation example. I know that the documentation goes on to talk about "Message Sinks" and whatnot, but I could've sworn I saw the message in the Output window of visual studio. In my real project this seems to work only erratically.

I know I can click the "Output" hyperlink after selecting a test and see it, but that's just one step extra, and that output doesn't have a monospace font either (which I'd like to have).

See this:

How do I configure xUnit to provide output in the Output window?


回答1:


After typing the question and fiddling around some more, the completely obscure solution popped up: only tests that fail show ITestOutputHelper output in the Output window.

Try changing the assertion to Assert.True(false); and you'll get this:

Not sure why that's the default, or how you'd change it.



来源:https://stackoverflow.com/questions/53795413/output-from-xunit-tests-run-with-visual-studio-test-runner-not-shown-in-output-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!