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

Notification

Icon
Error

Setting Console output and error report
Vincent
#1 Posted : Tuesday, October 23, 2018 9:18:34 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/1/2017(UTC)
Posts: 4
Location: France

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I have the following NUnit test:

[Test]
public void Test()
{
StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
standardOutput.AutoFlush = true;
Console.SetOut(standardOutput);
Assert.That(1, Is.EqualTo(2));
}

The NCrunch Tests window reports that the test fails, but doesn't show me the assert error.

If I remove the console redirection, it works, the assert error is displayed.

How do I restore the output so that the assert error is displayed ?

(Of course, I am doing real stuff with the Console redirection, I simplified the example).

Using VS2015 Professional update 1 and Nunit 3.8.1
Remco
#2 Posted : Tuesday, October 23, 2018 10:19:27 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,476

Thanks: 717 times
Was thanked: 898 time(s) in 854 post(s)
Hi, thanks for sharing this issue.

Exceptions from failed assertions are output to NCrunch using the console output stream. To capture all exceptions thrown in an environment and all other data, NCrunch redirects the console output stream to its own internal buffer. By redirecting it yourself, you override NCrunch's own behaviour and capture the data yourself.

There isn't really much we can do about this. NCrunch can't coherently capture trace data without its console output stream in place. You'll still receive exceptions inline in your code coverage and the test will still fail, but no data will be reported for the test inside the Tests Window.
1 user thanked Remco for this useful post.
Vincent on 10/24/2018(UTC)
Vincent
#3 Posted : Wednesday, October 24, 2018 8:52:08 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/1/2017(UTC)
Posts: 4
Location: France

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I found a workaround: wrapping the assert in a try catch, writing the exception to the Console.Error output stream and rethrowing it:

Code:
try
{
    StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
    standardOutput.AutoFlush = true;
    Console.SetOut(standardOutput);
    Assert.That(1, Is.EqualTo(2));
}
catch(Exception e)
{
    Console.Error.WriteLine(e.ToString());
    throw;
}
1 user thanked Vincent for this useful post.
Remco on 10/24/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.031 seconds.