【问题标题】:How to Fail Build on NUnitTest Fail using Powershell如何使用 Powershell 失败构建 NUnitTest 失败
【发布时间】:2017-07-28 03:15:30
【问题描述】:

我正在使用 NUnitConsole3 测试运行器运行所有 unittest.dll,它会在成功构建后生成 xml TestResult 报告。如果任何单元测试失败,我将如何使构建失败?

下面是运行单元测试的脚本

$SourceDir = "C:\Users\M1036083\Source\Repos\TestSitecoreProject"


$OutDir = "C:\Builds\2\Demo\bin"



## ------------------------------------------------------------------------------
## Set Nunit Tool path 
## ------------------------------------------------------------------------------

$nunit = "$SourceDir\NUnit.Console-3.6.1\nunit3-console.exe"


## ------------------------------------------------------------------------------
## Get all the Test dlls from the output directory 
## ------------------------------------------------------------------------------

$tests = (Get-ChildItem $OutDir -Recurse -Include Demo.*Tests.dll)


## ------------------------------------------------------------------------------
## Run all the tests and generate report in XML format
## ------------------------------------------------------------------------------

& $nunit --inprocess $tests --noheader --work="$OutDir"  

【问题讨论】:

    标签: powershell build nunit


    【解决方案1】:

    您可以检查 Console runner 退出代码,因为它返回失败的总数(失败、无效或导致错误测试的总和,代码为 here)。
    要在 powershell 中获取退出代码,只需使用 $LASTEXITCODE(因为您正在运行 nunit in-process,更多详细信息 here)。
    预计控制台运行程序会返回以下代码:

    • 0 - 所有测试通过
    • 高于 0 - 失败次数
    • 低于 0 - 控制台运行器中的错误:无效的程序集 (-1)、参数 (-2) 或夹具 (-4) 或意外错误 (-100)

    【讨论】:

      猜你喜欢
      • 2015-12-23
      • 1970-01-01
      • 2011-01-22
      • 2021-11-11
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多