Can't Get Code Coverage For Dotnet

Hi. I use Gitlab CI for automation. My main projects are on .NET Framework and Blazor. Tests are on .NET Core. this is my script for one of the projects.I have analyze for all code include tests but not code coverage:
variables:
SONAR_USER_HOME: “${CI_PROJECT_DIR}/.sonar” # Defines the location of the analysis task cache
GIT_DEPTH: “0” # Tells git to fetch all the branches of the project, required by the analysis task

stages:
  - build
  - test
  - sonarcloud-check
  - documentation
        
before_script:
 - Set-Variable -Name "time" -Value (Get-Date -Format "%H:%m")
 - echo ${time}
 - echo "started by ${GITLAB_USER_NAME}"

build:
  stage: build
  only:
    - branches
  script:
    - echo "running scripts in the build job"
    - choco feature enable -n=allowGlobalConfirmation
    - choco install netfx-4.6.2-devpack
    - choco install dotnetcore-sdk
    - nuget restore -ConfigFile .\nuget.config 
    - msbuild ".\ProjMode\ProjMode.csproj" /p:DeployOnBuild=true /p:PublishProfile="Local Publish" /p:WarningLevel=0
    - dotnet build ".\ProjMode.Tests\ProjMode.Tests.csproj" --configuration Release
  artifacts:
    paths:
      - Publish
      - .\ProjMode.Tests\bin\Release\netcoreapp3.1\**
    expire_in: 1 day
  after_script:
    - Remove-Item -Recurse -Force .\packages\    
    
test:
  stage: test
  only:
    - branches
  script:
    - New-Item -Name "TestResults" -ItemType "directory" -Force
    - '& "$env:VS_TEST" ".\ProjMode.Tests\bin\Release\netcoreapp3.1\ProjMode.Tests.dll" /InIsolation /logger:"html;logfilename=ProjMode.Tests.Results.html" /logger:"trx;logfilename=trx.trx"'
    - ./getcoverage.ps1
  artifacts:
    paths:
      - TestResults\**
    expire_in: 1 week
    when: always
  dependencies:
    - build
  timeout: 5h
  after_script:
    - taskkill /im chromedriver.exe /f


sonarcloud-check:
  stage: sonarcloud-check
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  dependencies:
    - build
    - test
  script:    
    - SonarScanner.MSBuild.exe begin /k:"org_rgb2compliant" /o:"org" /d:sonar.verbose=true /d:sonar.host.url="https://sonarcloud.io"  /d:sonar.login="vreeet"   
    - nuget restore -ConfigFile .\nuget.config
    - MsBuild.exe ./  /t:Rebuild
    - SonarScanner.MSBuild.exe end /d:sonar.login="vreeet"

.sonarcloud.properties:
# Path to sources
sonar.sources=.
#sonar.exclusions=
#sonar.inclusions=

Path to tests

sonar.tests=.
#sonar.test.exclusions=
#sonar.test.inclusions=

Source encoding

sonar.sourceEncoding=UTF-8

Exclusions for copy-paste detection

#sonar.cpd.exclusions=

Hi @vladimir_petukhov

You can check this guide which may help you setting up your code coverage.

HTH,
Mickaël

No I can understand how to make it.In my case I use selenium E2E and Nunit.I can’t understand wich properties, where to write.

Note that you cannot mix multiple coverage report technologies for a single project. Also, beside technologies described in the guide, other coverage for .NET are not supported.

HTH,

1 Like