Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Log output within OneTimeSetup? [NUnit]
GreenMoose
#1 Posted : Tuesday, June 5, 2018 10:56:20 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
[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.
Remco
#2 Posted : Tuesday, June 5, 2018 11:31:42 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
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.
GreenMoose
#3 Posted : Tuesday, June 5, 2018 11:38:29 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
Quote:
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)

Code:

[SetUpFixture]
internal class SetupTestSuite
{
[OneTimeSetUp]
public void SetupTestSuiteSetUp()
{
//Does not end up in NCrunch test output
Console.Write("One time setup!\n");
}
}
Remco
#4 Posted : Tuesday, June 5, 2018 12:33:45 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
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.
1 user thanked Remco for this useful post.
GreenMoose on 6/5/2018(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.037 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download