Unit Test Runner does not show console output

Hello,

Rider does not output any logs in the Unit Test window. When I run the tests using the CLI it does output logs. I run rider on an M1 Mac.

Output in Rider (empty):

While running it in the CLI confirms there is actually output:

dotnet test --filter "FullyQualifiedName~CreateDispatch_ShouldCreateDispatch_ForMinimumFieldsSupplied"

<text removed for privacy reasons>

Starting test execution, please wait...
 
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]
Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 6.0.7 initialized 'WriteDbContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL:6.0.5+9d79af6e2586d5d28da253ac075706a5575a1743' with options: SensitiveDataLoggingEnabled DetailedErrorsEnabled
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (38ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory');
info: Microsoft.EntityFrameworkCore.Database.Command[20101]

Am I missing a setting to show the logs? 

2
14 comments

Hello Jorikvdwerf,

Could you please clarify the way the test output is produced? A sample code snippet would be perfect =)

0

I am having the same problem. When I run an NUnit test one by one, right-clicking it and select `Run Unit Test` or `Debug Unit Test`, I see the output from `Console.WriteLine("testing")`, when clicking on the individual test that have run. But when I run all tests on a class, I see no output in the console.

This makes it very hard to debug the test itself using plain std-out prints to the console (Console.WriteLine()).

I tried with TestContext.Out.WriteLine() as well, but it game no output as well.

When I run all the tests in a class from a command prompt with with the `dotnet test` command, I do see all my output. So I am just missing them inside Rider.

0
Thank you for the input. Unfortunately, I could not reproduce the behaviour either in Windows or MacOS with M1 chip. Would you please check if the issue is specific to a particular solution? If so, what is the target framework, unit test framework and how many tests there are?
Shall it reproduce in some dummy solution, will be happy if you could share it. Thank you!
0

I'm experiencing the same issue, xunit, serilog configured to print to console. When debugging, there is  Debug->Console tab that show the logs.  When I **run** the test,  output can't be found anywhere.

0

Hello Alexander Furer,

This behavior is caused by the way XUnit handles output via ITestOutputHelper, see Capturing Output in XUnit docs.. You have to use ITestOutput to see any output for an XUnit test. If you're using Serilog, consider using a sink that can write to ITestOutput, not unlike this one.

It might also be a good idea to have Rider/R# capture console output produced by XUnit test, I've submitted a new ticket for our development team to review this feature - https://youtrack.jetbrains.com/issue/RIDER-90245/Capture-console-output-in-XUnit-tests. You can upvote it and click Watch to monitor the progress of the issue.

Let me know if you have other questions. Have a good day!

1

Does it mean you have different setup for debug and run xunit tests? Because I do see logs printed to console when debugging it.

0

Btw, the logs are printed by the application (SUT), not by the test itself. When I run `dotnet test` in CI, the logs are visible as well

0

Hello Alexander Furer,

XUnit handles output differently from other test frameworks, please refer to XUnit documentation. Console output when debugging is not related to XUnit test output.

When you run dotnet test you see the whole unit test run log produced by the test runner. If you open the same log in Rider (Session Options | Diagnostics | Show Last Launch Log) you'll see the XUnit test output same as with dotnet test, e.g.:

15:15:31.685 |I| Output stream: info: TestLogOutput.XUnitTests[0]
      ILogger XUnit message
[15:15:31 INF] Serilog XUnit message
Console.WriteLine XUnit message

Whether the logs are printed by the system under test or the unit testing code is not important for XUnit. You have to use ITestOutputHelper to see any XUnit test output in the test output window in Unit Test Explorer. Alternatively you can use test launch logs to see any output not shown in the Explorer.

Above I have provided a link to the feature request that would allow Rider to capture any console output and display in in the Unit Test Explorer window. If it is still relevant for you, you can upvote the feature and subscribe for future updates. 

0

Ivan Skorikov , thanks, I know that xUnit uses output helper.

 My point  is that when I DEBUG the xUnit test , application logs are visible in debug console window (aplication logging is implemented with Serilog + console sink).

When I RUN the same test, the logs can't be found anywhere.

0

Can you please show the sessions' last logs in the panel which remains empty when running the tests :


 

0

Hello,

When I RUN the same test, the logs can't be found anywhere.

When you're debugging, you're looking at the debug console which contains the standard output stream. xUnit does not support capturing standard output out of the box (see the relevant issue in xUnit tracker), so currently Rider can't show that as well. The aim of the feature request linked above is to work around the limitation and capture output by other means. 

Can you please show the sessions' last logs in the panel which remains empty when running the tests :

Could you please clarify, do you mean that the panel you indicated on the screenshot should contain all output and results of the unit test group that is selected in the test session tree to the left?

0

so currently Rider can't show that as well.

The logs you see in Console are printed by SUT application (via Serilog Console sink).

 So I'm not sure  why are you saying that it's impossible.

 results of the unit test group that is selected in the test session tree to the left

Yes, can you please just show here whatever you have under `Session Options | Diagnostics | Show Last Launch Log`

0

Hello,

What you're seeing in the Debugger console is the stdout/stderr streams produced by executing SUT assemblies. xUnit does not support capturing those output streams, and in the Unit Test results window, Rider shows whatever output is received from xUnit upon running tests. At the moment of writing this, xUnit folks plan to introduce support for capturing output streams in xUnit 3.0 (see issue #1730 in the xUnit tracker). RIDER-90245 is essentially a request for workaround, i.e. capture the output elsewhere and display it in the Unit Test Results window.

Yes, can you please just show here whatever you have under `Session Options | Diagnostics | Show Last Launch Log`

Thank you for the clarification. Unfortunately, it's not possible at the moment. Since this suggestion concerns a broader range of scenarios, not just xUnit, I've filed a new request to implement this: RIDER-103826 Allow showing last launch log in the unit test results panel.

Let me know if you have any further questions.

0

What you're seeing in the Debugger console is the stdout/stderr streams produced by executing SUT assemblies. 

Still don't understand what the problem is to show the same output  when you RUN the test, if you are able to capture it in  DEBUG.

 

 

 

0

Please sign in to leave a comment.