【问题标题】:How to see a friendly report of unit tests using .Net Core and coverlet?如何使用 .Net Core 和 Coverlet 查看友好的单元测试报告?
【发布时间】:2019-01-25 10:13:16
【问题描述】:

我正在使用 Coverlet 和 .Net Core 开发 API,我开始进行单元测试(我为 .Net Core 找到的唯一工具是 Coverlet)。

我得到了报道,但我只能得到 jsonxml 等文件。

我需要查看 HTML 或更直观的东西才能快速处理测试。

这是我在终端上的当前输出:

+---------------------------+--------+--------+--------+
| Module                    | Line   | Branch | Method |
+---------------------------+--------+--------+--------+
| rede-merchants-cancel-api | 12,5%  | 0%     | 16,7%  |
+---------------------------+--------+--------+--------+

还有一部分输出带有json:

"Program.cs": {
  "Program": {
    "System.Void rede_merchants_cancel_api.Program::Main(System.String[])": {
      "Lines": {
        "9": 0,
        "10": 0,
        "11": 0
      },
      "Branches": []
    },
    "Microsoft.AspNetCore.Hosting.IWebHost rede_merchants_cancel_api.Program::BuildWebHost(System.String[])": {
      "Lines": {
        "14": 0,
        "15": 0,
        "16": 0
      },
      "Branches": []
    }
  }
}

【问题讨论】:

    标签: unit-testing testing .net-core automated-tests code-coverage


    【解决方案1】:

    我找到了答案,我首先尝试的是使用docker-dotnet-sonarscanner,但是我无法很好地设置,然后我采用了另一种方法:

    1. 安装coverlet,它为我提供了多种格式的.Net Core 代码覆盖率:json(默认)、lcovopencovercobertura
    2. 为 VSCode 安装一个插件,我可以在其中很好地查看代码覆盖率,它的名称是 coverage-gutters
    3. 使用coverlet docs上可用的命令以lcov格式输出代码覆盖率,以便能够与代码覆盖率插件一起使用。
    4. 额外 - 使用插件在 VSCode 而不是 CLI 上运行测试(我没有尝试过),使用 .Net Test Explorer 是可能的,但我认为有必要更改命令才能输出你的内容需要。

    【讨论】:

    • 如何使用coverage gutter来查看报告,因为它只支持查看html
    • @drowhunter 可以在 VSCode 或其他编辑器中查看 html
    【解决方案2】:

    如果您希望从带有源代码的代码覆盖结果中看到漂亮而干净的 HTML 报告,您应该尝试 Daniel Palme 的 ReportGenerator。 Coverlet 可以生成cobertura 类型的 XML 报告,而 ReportGenerator 可以从中生成 HTML 报告。 Here 你可以找到关于如何使用 Coverlet 和 ReportGenerator 的精彩分步教程。 Cobertura 报告可以在您的 CI/CD 管道期间使用this Jenkins 插件轻松处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-05
      • 2022-10-23
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多