.netpowershell.net-coredotnet-test

Break PowerShell Script when dotnet test fails


In a small PowerShell build script I build and test a .NET application.

I now want to prevent further steps in the script if the tests result in one or more failures.

I tried to get the result of the test like this:

$exitcode = dotnet test  .\Domain.Tests
Write-Host "result $exitcode" 

but unfortunately it doesn't return an exit code indicating success I just get the test testing description.

Is there a better way then parsing the string output for the failed tests count?


Solution

  • There is a $lastexitcode automatic variable, you can check that for the exit code.