Display Code Coverage on Overview Page

I'm wondering if it is possible to somehow display the code coverage % on successful builds. We are currently using dotCover.

When a build fails, it shows a message like this:
Tests passed: 365; percentage of statement coverage 99.456 is 0.544 less than the provided threshold…


When it succeeds, it shows this:
develop    #170      Tests passed: 378


What I'd like it to show when it succeeds is this:
develop #170      Tests passed: 378; percentage of statement coverage is 54.12


This is all in efforts to slowly bring awareness to our code base's code coverage at a glance, so that we can begin to start putting in metrics on some of our other solutions.

Any ideas on how to make this happen?

 

1
2 comments

Hi, and sorry for the delay.

Posting the message result for the build is delegated to the specific runner, so the first thing is that you would need to check which runner you are using for that. There is a way to affect the build result message, described here: https://confluence.jetbrains.com/display/TCD10/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingBuildStatus

What you could do if the runner doesn't do it automatically is either add a last build step that takes the dotcover reports and parses them to retrieve the code coverage, then post it by yourself, or create your own build runner that posts it automatically.

0

Example

  1. Add to csproj (VS2017 format)
    <DotNetCliToolReference Include="JetBrains.dotCover.CommandLineTools" Version="2018.2.3" />
  2. Create Powershell runner
  3. Set Working directory to:
    %system.teamcity.build.tempDir%
  4. Set Script to
    Source code
  5. Set Script source
    $userProfile = "%env.USERPROFILE%"
    $dotcoverPath = "$userProfile\.nuget\packages\jetbrains.dotcover.commandlinetools\2018.2.3\tools\dotCover.exe"
    $codeCoverageJsonFilePath="code_coverage_report.json"
    $codeCoverageReportFile = (Get-ChildItem -Filter dcvr.*.tmp -Recurse | Select-Object -First 1)

    if($null -eq $codeCoverageReportFile) {
    Write-Host "No *.dcvr dotcover file found, exiting script."
    return
    }

    $codeCoverageReportFilePath = $codeCoverageReportFile.FullName
    Write-Host Found coverage report "$codeCoverageReportFilePath"

    Write-Host Converting coverage report to "$codeCoverageJsonFilePath"
    & $dotcoverPath report /Source="$codeCoverageReportFilePath" /Output=$codeCoverageJsonFilePath /ReportType=JSON

    $codeCoverageObj = (Get-Content $codeCoverageJsonFilePath | Out-String | ConvertFrom-Json)
    $codeCoveragePct = $codeCoverageObj.CoveragePercent
    Write-Host "##teamcity[buildStatus text='{build.status.text}. Code coverage: $codeCoveragePct%%.']"

It should be possible to change the build status more easily, testing this was slow, the method is also brittle.

0

Please sign in to leave a comment.