Daily Usage Issues

Log output within OneTimeSetup? [NUnit]

Started by GreenMoose on 7,647 views

[v3.17.0.2]

According to issue https://github.com/nunit/nunit/issues/1062 for nunit-console runner, there should be some means to log output in an OneTimeSetup method:

CharliePoole wrote:
To summarize, NUnit supports two kinds of output: standard and immediate.

Standard output is produced using Console.Write and TextContext.Write. The text is attached to the test result.

Immediate output is produced by Console.Error, TestContext.Error and TestContext.Progress. It is displayed immediately when received.

Standard output comes to the console runner at the end of the test. It is displayed for test cases but not currently for suites. The OneTimeSetUp is associated with the suite (fixture). Normally, the console only displays info from the fixture if the OneTimeSetUp fails.


I cannot get it to work with NCrunch though (i.e. by using Console.Error or TestContext.Progress), is there a way I can log output from an OneTimeSetup method (which I ensure via static var it is one time only) with NCrunch?

Thanks.

*Edit: It see the output from Fixture constructors, including static ones.

Edited

Under NCrunch, this documentation isn't completely accurate. This is because NCrunch actually seizes the Console stream out from under NUnit and takes control over it. For this reason, using Console.Write or Debug.Write will always result in the trace output being captured in the NCrunch log, regardless of whether this is in a OneTimeSetUp method or in a test, and regardless of the result of the test/setup.

We don't have any handling for TestContext.Progress at the moment, but it may be possible to add this. I've added a task to the backlog to address this in the near future. I thought we'd already handled it actually.
For this reason, using Console.Write or Debug.Write will always result in the trace output being captured in the NCrunch log, regardless of whether this is in a OneTimeSetUp method or in a test, and regardless of the result of the test/setup.

So then it should appear in test output with NCrunch when I use Console.Write ? I don't see that behavior here (net core 2 test though)


    [SetUpFixture]
    internal class SetupTestSuite
    {
        [OneTimeSetUp]
        public void SetupTestSuiteSetUp()
        {
            //Does not end up in NCrunch test output
            Console.Write("One time setup!\n");
        }
    }
This will work when applied on a normal fixture, but a SetUpFixture is special. This is because according to NCrunch, A SetUpFixture isn't actually a test. It has no representation in the actual set of test results, therefore it cannot hold a result or a trace output.

Post a reply

Log in to reply.