I have my .Net project on Github setup in sonarcloud. The code coverage scan is working, however, the workflow no longer fails due to a failing test. In my setup prior to sonarqube the workflow will fail after dotnet test has a failing test. Now that dotnet test is wrapped inside the sonarscanner the workflow is successful even if there is a failing test. How do I scan my code and have the workflow fail when a test fails? I’m using Coverlet to generate the coverage report.
It looks like the problem is that dotnet test is not the last command in the powershell script. The $LASTEXITCODE of dotnet test is therefore overwritten by dotnet-sonarscanner end and the script returns with “exit code = 0”.
You should try
dotnet test
$testResult = $LASTEXITCODE
dotnet-sonarscanner end
exit $testResult