I starting to pull my hair because I can’t get the coverage to work. I have read documents on sonarcloud, visual studio, forums both here and stack, asked chatgpt etc etc. I can generate a testfile as you will see in my workflow. Here is the workflow
name: SonarCloud
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Install dotnet-coverage tool
run: dotnet tool install --global dotnet-coverage
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"lind-exe_Statify" /o:"lind-exe" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="coverage.xml"
dotnet build --no-incremental
dotnet test # Run your tests
# Collect coverage using dotnet-coverage in Cobertura and output to coverage.xml
dotnet-coverage collect "dotnet test" -f cobertura -o "coverage.xml"
# Display content of coverage.xml for debugging
Get-Content -Path "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
When I build and do the debugg part to se the file I find it
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 12, Skipped: 0, Total: 12, Duration: 57 ms - Statify.Tests.dll (net7.0)
Code coverage results: coverage.xml.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<coverage line-rate="0.3877551020408163" branch-rate="0.10576923076923077" complexity="420" version="1.9" timestamp="1701428294" lines-covered="266" lines-valid="686" branches-covered="11" branches-valid="104">
Then when I want Sonarcloud to upload it it cannot read the test report, It seems it want a JaCoCo?
INFO: Sensor JaCoCo XML Report Importer [jacoco]
3455INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
3456INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
And my coveragereport get this:
WARN: Could not import coverage report ‘.\coverage.xml’ because ‘Only dotCover HTML reports which start with “” are supported.’. Troubleshooting guide: [Coverage] Troubleshooting guide for .NET code coverage import
I have only worked with workflows for 3 weeks beside building a project. I’m studying a .NET course and have only studied for 1 year and 3 months. So this is kinda confusing. How do I get the code cevarge to display on Sonarcloud.