Home > Software design >  Coverlet generated coverage.cobertura.xml empty source full path in filename
Coverlet generated coverage.cobertura.xml empty source full path in filename

Time:03-30

It works fine in most of my projects, but I have one where the coverage.cobertura.xml is generating like:

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="0.8" version="1.9" timestamp="1648222473" lines-covered="17" lines-valid="17" branches-covered="8" branches-valid="10">
  <sources>
    <source>/</source>
  </sources>
  <packages>
    <package name="LoggerService" line-rate="1" branch-rate="0.8" complexity="10">
      <classes>
        <class name="Tickett.ObjectRenderer" filename="builds/tickett_dlls/logger_service/LoggerService/ObjectRenderer.cs" line-rate="1" branch-rate="0.8" complexity="10">

Instead of something like:

<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="0.8" version="1.9" timestamp="1648222473" lines-covered="17" lines-valid="17" branches-covered="8" branches-valid="10">
  <sources>
    <source>/builds/tickett_dlls/logger_service/</source>
  </sources>
  <packages>
    <package name="LoggerService" line-rate="1" branch-rate="0.8" complexity="10">
      <classes>
        <class name="Tickett.ObjectRenderer" filename="LoggerService/ObjectRenderer.cs" line-rate="1" branch-rate="0.8" complexity="10">

My command looks like:

dotnet test -v=normal /p:CollectCoverage=true --logger "junit;LogFilePath=TestOutput.xml" --collect:"XPlat Code Coverage

I've compared everything I can think of but can't for the life of me figure out what's causing this subtle difference (which I think is causing GitLab not to be able to interpret the report)

CodePudding user response:

I figured it out by digging into the source of coverlet. I think it's this line:

https://github.com/coverlet-coverage/coverlet/blob/ebbf0424495de04e334beaabf626244fe9b80b06/src/coverlet.core/Reporters/CoberturaReporter.cs#L189

The tldr; my project only contains a single class to be analysed and it looks like the process of determining the base path requires at least 2 classes.

I will either:

  • remove an exclusion I currently have in place for one of the classes from test coverage
  • split the only class currently being analysed in two; or
  • add a simple sed command after the report is generated to "fix it up"

I have added a note to an existing issue in the project to see whether it should be considered a bug and if/how we might improve the way it's handled (potentially just allowing an argument/parameter to "hardcode" the source.

  • Related