我有一个 PS 脚本,我已成功使用它来运行和处理 NUnit 2.6.3 的结果。我最近升级到 NUnit 3.2.1 并且在将参数传递给 NUnit 可执行文件时遇到问题。该脚本是从 Octopus deploy 调用的,如下所示:
RunTests.ps1 -NunitArgs "--where cat==QuickTests" -OutputPath "workdir"
参数在这里处理:
param(
[string]$OutputPath = "testResults",
[string]$NunitArgs = "nunitOptions"
)
调用 NUnit(用一行来回显命令):
function GetNUnitConsolePath
{
return join-path -path ${env:ProgramFiles(x86)} -childpath "NUnit-3.2.1\bin\nunit3-console.exe"
}
...
Write-Host "Executing: $(GetNUnitConsolePath) Test.dll $NunitArgs --work==$OutputPath"
& $(GetNUnitConsolePath) Test.dll $NunitArgs --work==$OutputPath
结果:
Executing: C:\Program Files (x86)\NUnit-3.2.1\bin\nunit3-console.exe Test.dll --where cat==QuickTest
s --work=workdir
NUnit Console Runner 3.2.1
Copyright (C) 2016 Charlie Poole
Invalid argument: --where cat==QuickTests
以下代码行按 PS 脚本的预期工作:
& $(GetNUnitConsolePath) Test.dll --where cat==QuickTests --work=workdir
测试运行,类别过滤器和工作目录按预期设置:
NUnit Console Runner 3.2.1
Copyright (C) 2016 Charlie Poole
Runtime Environment
OS Version: Microsoft Windows NT 6.3.9600.0
CLR Version: 4.0.30319.34209
Test Files
Test.dll
Test Filters
Where: cat==QuickTests
Run Settings
WorkDirectory: workdir
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETFramework,Version=v4.5
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 8
Test Run Summary
Overall result: Passed
我也试过:
$arg1 = 'Test.dll'
$arg2 = '--where cat==QuickTests'
$arg3 = '--work=workdir'
Write-Host "Executing: $(GetNUnitConsolePath) $arg1 $arg2 $arg3"
& $(GetNUnitConsolePath) $arg1 $arg2 $arg3
这导致来自 NUnit 的相同输出:
Executing: C:\Program Files (x86)\NUnit-3.2.1\bin\nunit3-console.exe Test.dll --where cat==QuickTest
s --work=workdir
NUnit Console Runner 3.2.1
Copyright (C) 2016 Charlie Poole
Invalid argument: --where cat==QuickTests
我是一个 PS 菜鸟,所以希望这是我在脚本中忽略的明显内容。我还尝试了使用 -ArgumentList 的 Invoke-Command 的各种迭代,但没有得到任何结果。感谢所有建设性的建议 - 谢谢!