nunit3-vs-adapter icon indicating copy to clipboard operation
nunit3-vs-adapter copied to clipboard

Console.WriteLine statements in "OneTimeSetUp" and "OneTimeTearDown" is not captured

Open rprouse opened this issue 8 years ago • 8 comments

Given this test fixture:

    [TestFixture]
    public class TestClass
    {
        [OneTimeSetUp]
        public void FixtureSetup ()
        {
            Console.WriteLine ("FixSetUp");
        }

        [SetUp]
        public void SetUp ()
        {
            Console.WriteLine ("SetUp");
        }

        [TearDown]
        public void TearDown ()
        {
            Console.WriteLine ("TearDown");
        }

        [OneTimeTearDown]
        public void FixtureTearDown ()
        {
            Console.WriteLine ("FixTearDown");
        }

        [Test]
        public void Test ()
        {
            Console.WriteLine ("Test");
        }
    }

It would be expected that Console.WriteLine ("FixSetUp"); and Console.WriteLine ("FixTearDown"); are correctly printed to test results window.

@GrimaceOfDespair commented on Tue Nov 15 2016

just fyi, this is my VS console output on these tests:

image


@CharliePoole commented on Tue Nov 15 2016

@GrimaceOfDespair Are you running vstest.console? That would be a completely different issue. None of these writes are displayed directly. They are events that each runner has to handle. This issue was about how the nunit console runner handles it. We probably need another for the nunit VS adapter.


@GrimaceOfDespair commented on Tue Nov 15 2016

I was under the impression, again wrongly, that the Standard Output was "just a capture" of the same stuff that came out of the console. I guess in theory it is, but in practice, there's a difference.

Apparently, I'm a bit confused as to which project I should be talking to whom, though that probably will most of the time be you :) You want me to file an issue with nunit3-vs-adapter?


@rprouse commented on Tue Nov 15 2016

@GrimaceOfDespair I will copy this issue across to the adapter project and edit it to reflect your issues.

rprouse avatar Nov 15 '16 13:11 rprouse

@GrimaceOfDespair, your issue is now in the adapter repo. Feel free to subscribe to it.

rprouse avatar Nov 15 '16 13:11 rprouse

That's even worse : If you write a lambda using Console.WriteLine() ; and use it to setup objects during the OneTimeSetup ; Then when the lambda is invoked during the tests, the Console.WriteLine() output is not captured.

That's only a funny implementation detail, but is it time consuming when you wonder why it won't output something.

antibarbie avatar Oct 17 '18 13:10 antibarbie

@antibarbie Not sure what "That's even worse:" is referring to in the thread.

However, any Console.WriteLine() during OneTimeSetUp is captured and becomes part of the XML output of the test you are setting up. That would normally be the fixture, of course, not an individual test case. If you are using a runner that ignores fixture output, then you never see it. So, for example, you would not see it in using the VS adapter to run tests, while you would see it when running the nunit console.

CharliePoole avatar Oct 17 '18 15:10 CharliePoole

Will this ever be fixed? In Visual Studio, MSTest simply displays the console output in ClassInitialize in the first test case. I am not sure if it is a feature or a bug but it is better than none in the imperfect world.

MutatedTomato avatar Nov 23 '18 14:11 MutatedTomato

Any timeline for this issue. it has been over 5 year.

xuxiankun avatar Oct 27 '21 23:10 xuxiankun

Any timeline for this issue. it has been over 5 year.

We accept PR fixes 😉

rprouse avatar Oct 30 '21 02:10 rprouse