Vstest.console 在 powershell 和 Action Based on results

Vstest.console in powershell and Action Based on results

我正在尝试 运行 在 PowerShell 中使用 vstest.console 进行一些功能单元测试,如果任何测试失败,我将执行特定操作(在这种情况下,它会回滚安装)。我该怎么做。

这是我拥有的 PowerShell 脚本的当前内容。

$command = "<path_to_vstest_directory>\vstest.console.exe"
$arguments = @('<test dll>', '/Tests:"<name_of_specific_test_to_run>"')
&$command $arguments

您可以使用 Start-Process cmdlet 来控制已执行的进程:

$command = "<path_to_vstest_directory>\vstest.console.exe"
$testDll = "Path\with space\test.dll"
$testName = "name_of_specific_test_to_run"
$process = Start-Process $command -ArgumentList "`"$testDll`" /Tests:`"$testName`"" -PassThru -Wait

之后,您可以评估存储在$process.ExitCode中的退出代码。如果需要,您还可以重定向 stdoutstderr