Redirection of Console.WriteLine to ITestOutputHelper WriteLine #2649
sjanisz
started this conversation in
Feedback Request
Replies: 1 comment
-
Yes, that's exactly why we don't capture Console anymore: https://xunit.net/docs/capturing-output
This has to do with Console being a shared, static resource. There's no way to allocate a separate static Console for each test. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I will copy paste my question which I have asked on SO (https://stackoverflow.com/questions/75172528/xunit-redirection-of-console-writeline-to-itestoutputhelper-writeline):
I have problem with solution from this answer: https://stackoverflow.com/a/47529356/8611327
The problem is that when I use parallel testcases execution Console.WriteLine is common for all running test instances and logging is not assigned to specific testcase, so I see logs written under last testcase that have instantiated WriteLineConverter and set it as Console output:
WriteLineConverter writeLineConverter = new WriteLineConverter(_output);
Console.SetOut(writeLineConverter);
I need to use Console.WriteLine because I have a lot of nested classes like services, then access to database, sending http requests etc where I am logging timestamps and requests, I need to be able to connect theses logs with specific testcases because in parallel scenario logs from testcases are mixed.
Eventually is it possible to somehow run tests so each testcase has its separate stack of variables rather than shared stack used by all testcases?
Beta Was this translation helpful? Give feedback.
All reactions