0

我正在使用 Scala 项目中的覆盖率。在构建期间,我生成覆盖率 HTML 和 XML 报告。我需要解析 XML 文件(即scoverage.xml)以提取每个类的指标:* 行覆盖率:覆盖的数量与总数 * 语句覆盖率:覆盖的数量与总数 * 分支覆盖率:覆盖的数量与总数 * 函数覆盖率:覆盖的数量与总数

查看 scoverage repo,我看到报告是由ScoverageXmlWriter.scala生成的,但没有记录!

因此,这是该语句的示例输出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>

属性是什么意思?是line对应文件中的行号吗?和代表start什么end

4

1 回答 1

0

我在 sbt 插件代码本身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

我只需要解析 XML,同时考虑上面的代码片段来重新计算计数(例如分支计数与覆盖)。

于 2020-05-07T01:44:58.110 回答