2017-07-27 118 views
0

我使用NUnitConsole3測試運行器運行所有unittest.dll,並且在成功構建後生成xml TestResult報告。如果任何單元測試失敗,如何構建失敗?如何在NUnitTest上構建失敗使用Powershell失敗

下面給出的是腳本運行單元測試

$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" 

回答

0

您可以在控制檯運行退出代碼使用支票,因爲它返回的故障總數(失敗,無效的總和或導致錯誤測試,代碼是here)。
要在PowerShell中獲得退出代碼,只需使用$LASTEXITCODE(因爲您正在運行nunit進程,更多詳細信息請參閱here)。
期望從控制檯亞軍以下返回代碼:

  • 0 - 失敗的次數
  • 低於0 - - 錯誤控制檯運行通過
  • 0以上的所有測試:無效大會(-1),參數(-2)或夾具(-4)或意外錯誤(-100)