[英]How to Fail Build on NUnitTest Fail using Powershell
I am running all the unittest.dll using NUnitConsole3 test runner and it generates xml TestResult report after successful build.How will i make the build fail if any of the unit test fails? 我正在使用NUnitConsole3测试运行程序运行所有unittest.dll,成功构建后会生成xml TestResult报告。如果任何单元测试失败,我将如何使构建失败?
Given below is the script to run Unit test 下面给出的是运行单元测试的脚本
$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"
You can use a check on the Console runner exit code, as it returns total number of failures (the sum of failed, invalid or resulted in error tests, code is here ). 您可以对控制台运行程序退出代码进行检查,因为它返回失败的总数(失败,无效或导致错误测试的总和,代码在此处 )。
To get the exit code in powershell just use $LASTEXITCODE
(since you're running nunit in-process, more details here ). 为了获得在PowerShell中的退出代码只使用
$LASTEXITCODE
(因为你正在运行的进程NUnit的,更多的细节在这里 )。
Expect the following return codes from console runner: 期望控制台运行程序提供以下返回代码:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.