简体   繁体   English

在mstest的测试过程中从子进程中捕获stdout

[英]Capturing stdout from a subprocess run during a test in mstest

I'm using MSTest to run some tests (in C#). 我正在使用MSTest运行一些测试(在C#中)。 One of the routines I'm testing creates a new process and that process often dumps some output stdout. 我正在测试的例程之一创建了一个新进程,该进程通常会转储一些输出stdout。 I'd like to capture that output in the test. 我想在测试中捕获该输出。 While it isn't important to see if the test failed, it is very helpful in figuring out why the test failed. 虽然查看测试是否失败并不重要,但对弄清测试为什么失败非常有帮助。 How can I do this? 我怎样才能做到这一点?

Some details. 一些细节。 Unfortunately, I can't touch the code that is creating the process. 不幸的是,我无法触及创建过程的代码。 Worse, it is C++, and it is being called via a C++/CLI wrapper. 更糟糕的是,它是C ++,并且正在通过C ++ / CLI包装器进行调用。 If I create a .NET console app (in C#) then the stdout of the subprocess I want to capture does appear in the window of the console app when it makes the call. 如果我创建一个.NET控制台应用程序(使用C#),则要捕获的子进程的标准输出在进行调用时确实会出现在控制台应用程序的窗口中。 When I run the same code in the MSTest context the sub-process creation pops up a new window, and the subprocess dumps its output in that window. 当我在MSTest上下文中运行相同的代码时,子过程创建会弹出一个新窗口,并且子过程将其输出转储到该窗口中。 It is that output I'd like to capture if at all possible. 如果可能的话,就是我想要捕获的输出。

Many thanks! 非常感谢!

如果在测试结果完成后双击测试结果,您还将看到一个包含stdout的报告页面。然后您可以在此处看到将一个流程对象的stdout重定向到另一个流程对象的stdin,如何将子流程stdout重定向并仅对此进行镜像在测试的标准输出中(即调用Console.Write())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM