Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThiagoBarradas/d59ee9a2dbb4c2b5ce5b96562dc97725 to your computer and use it in GitHub Desktop.
Save ThiagoBarradas/d59ee9a2dbb4c2b5ce5b96562dc97725 to your computer and use it in GitHub Desktop.
Sonarqube - send dotnet code analysis and code coverage
# Install sonarqube scanner / reporter
dotnet tool install --global dotnet-sonarscanner
# Install dotnet tools to generate test report
dotnet tool install --global coverlet.console
dotnet add package coverlet.msbuild
# Start sonarqube process
dotnet build-server shutdown
dotnet sonarscanner begin /o:${SONAR_ORG_KEY} /k:${SONAR_PROJECT_KEY} /v:${VERSION} /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=${SONAR_TOKEN} /d:sonar.cs.opencover.reportsPaths="opencover.xml"
# Build solution
dotnet restore
dotnet build ./MySolution.sln
# Running unit tests - 'opencover ' output format
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=coverage /p:Exclude=[xunit.*]* ./MySolution.sln
mv ./MyProject.Tests/coverage.opencover.xml opencover.xml
# Send test report result to codeclimate
dotnet sonarscanner end /d:sonar.login=${SONAR_TOKEN}
@lorddev
Copy link

lorddev commented Apr 21, 2022

What if you have more than one test project? How do you do

mv ./MyProject.Tests/coverage.opencover.xml opencover.xml 

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment