简体   繁体   中英

how to interpret scoverage.xml report

I am using the scoverage in Scala project. During the build, I generate coverage HTML and XML reports. I need to parse the XML file (ie scoverage.xml ) to extract metrics for each class on: * lines coverage: number of covered ones vs total * statements coverage: number of covered ones vs total * branches coverage: number of covered ones vs total * functions coverage: number of covered ones vs total

Looking at the scoverage repo, I see that the report is generated by ScoverageXmlWriter.scala but it is not documented!!

So here is an example output of the statement tag :

<statement package="<package>" class="<class>" class-type="Object" full-class-name="<package>.<class>" source="/path/to/<package>/<class>.scala" method="compileScala" start="350" end="350" line="18" branch="false" invocation-count="1" ignored="false">
</statement>

What does the attribute means? Is line corresponding to the line number in the file? and what's start and end stands for?

I found the answers in the sbt plugin code itself coverage.scala#L159-L168

  def invokedStatements: Iterable[Statement] = statements.filter(_.count > 0)
  def invokedStatementCount = invokedStatements.size
  def statementCoverage: Double = if (statementCount == 0) 1 else invokedStatementCount / statementCount.toDouble
  def statementCoveragePercent = statementCoverage * 100
  def statementCoverageFormatted: String = twoFractionDigits(statementCoveragePercent)
  def branches: Iterable[Statement] = statements.filter(_.branch)
  def branchCount: Int = branches.size
  def branchCoveragePercent = branchCoverage * 100
  def invokedBranches: Iterable[Statement] = branches.filter(_.count > 0)
  def invokedBranchesCount = invokedBranches.size

I simply had to parse the XML while considering the snippet above to recalculate the counts (eg branches count vs covered).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM