2

(对不起,奇怪的标题,还没有想出更好的东西..)

背景

我使用 nunit-console 来测试我的程序集。它被称为这样(简化):

function Test-ByNunit {
    param($assembly, $tempFile = 'c:\temp\nunit.xml')
    & <path-to-nunit-console> $assembly /nologo /xml:$tempFile @othparam 
}
Test-ByNunit c:\temp\myAssembly.dll

我对此没有任何问题,它工作正常。

问题

nunit-console应该输出它的消息。这意味着 - 如果没有捕获,它应该将它们发送到屏幕,否则它可以存储在文件中 ( Test-ByNunit $dll | set-content path)

PSObject我想以对象数组的形式返回关于每个运行的测试用例的信息(信息存储在 /xml 文件中) 。

问题

您有任何提示如何返回信息并仍然让 nunit 输出其消息吗?
如果我只是将其写入输出,该函数将返回字符串数组(从 nunit-console 输出)和我的对象数组。然后重定向到输出文件也将存储我的对象,但我只想在控制台窗口中显示它们。

唯一可行的方法是使用[ref],但我想避免它。

(这不仅与 nunit-console 有关,而且当然是一般性问题)

4

1 回答 1

2

如果我完成了任务,那么Out-Host应该会有所帮助:

function Get-WithOutHost {
    # external output is redirected to the host
    cmd /c dir | Out-Host
    # normal output to be reused later
    Get-Process
}

# call    
$result = Get-WithOutHost

# now $result holds the data to use, external output is on the screen

编辑:当然这还不够,如果外部输出也应该被重用,而不仅仅是显示

于 2010-05-06T10:40:02.200 回答