powershell - 从 Powershell 运行 NUnit 3

标签 powershell nunit-console nunit-3.0

我有一个 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 的各种迭代,但没有得到任何结果。感谢所有 build 性的建议 - 谢谢!

最佳答案

我在 article 中的练习 #5 取得了很大的成功过去尝试在powershell中执行程序时。但是,我想几天前我遇到了类似的问题。我不得不处理一个论点 --deployat="yyyy-MM-dd HH:mm:ss"作为单个输入,dd HH 之间的空格正在杀了我。我最终成功使用 Invoke-Expression , #2 选项在文章中提到。正如文章中所说,请小心,这是一种危险的做法。

关于powershell - 从 Powershell 运行 NUnit 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37038093/

相关文章:

mysql - PowerShell 不会逐行迭代 MySQL 结果 - 为什么?

powershell - Powershell获取服务问题

powershell - 将字符串拆分为两个数组

teamcity - 使用 NUnit 3 时,为什么我在 TeamCity 9 上收到 "File type is not supported"?

visual-studio-2017 - 生成错误: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0 " or one of its dependencies

c# - 为什么 [SetUpFixture] 中的 [OneTimeSetUp] 在 (Test,TestCaseSource()) 之后调用

powershell - 重定向到 'NUL' 失败 : FileStream will not open Win32 devices

nunit-3.0 - 如何使用 NUnit 和 dotCover 获取测试详细信息和覆盖率?

powershell - Powershell中来自外部exe和我的自定义对象的输出

testing - SpecFlow 2.0.0 上的 @Ignore 标记导致构建错误