【问题标题】:Vstest.console in powershell and Action Based on resultsPowershell 中的 Vstest.console 和基于结果的操作
【发布时间】:2020-04-16 00:07:02
【问题描述】:

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

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

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

【问题讨论】:

  • 自动变量$LASTEXITCODE包含最近执行的外部程序的退出代码; exit $LASTEXITCODE 允许您将该退出代码用作脚本。

标签: powershell vstest.console.exe


【解决方案1】:

您可以使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多