为什么 CodeCoverage.exe 会生成接近空的 .coverage 文件?
在我们的 Jenkins 管道中,我们使用 SonarQube 来报告代码覆盖率。运行所有单元/集成测试以生成 .coverage 文件后,我们需要分析该文件以创建“.coverage.coveragexml”,这最终是 SonarQube 用于解释代码覆盖率的内容。我们通过使用 CodeCoverage.exe 来完成此操作:
"C:\Program Files (x86)\Microsoft Visual Studio\2022\TestAgent\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"{somePath}\{someName}.coverage.coveragexml" "{somePath}\{someName}.coverage"
此命令似乎有效,但是当您运行 dir /s *.coveragexml
(在目录内)时,它会显示类似以下内容:
Directory of C:\jenkins\path\to\TestResults\coverageFile
03/22/2022 04:59 PM 64 ContainerAdministrator_DC420D3FA0BA_2022-03-22.16_46_43.coverage.coveragexml
1 File(s) 64 bytes
64 字节实际上没什么- 我相信这就是为什么我们的 SonarQube 指标显示我们现在覆盖率为零的原因。
我添加了相同的 dir
命令,只是这次是为了检查 .coverage
文件,而这些文件返回时只有 10 个字节 - 让我觉得这些文件本质上是空的。我看到这篇文章似乎是一个类似的问题。接受的答案说将平台类型从 x86 更改为 x64,但这对我来说不起作用。
用于运行测试的 vstest.console 命令是:
vstest.console /Parallel /EnableCodeCoverage /Logger:trx /Platform:x86 ".\somePath\Test.dll"
此问题最初是在我们对 Jenkinsfile 进行更改以在启动 CodeCoverage 可执行文件的命令中使用 Visual Studio 2022 而不是 2019(基础映像已更新)时开始出现的。
什么可能导致覆盖文件几乎/完全为空以及如何修复它?
In our Jenkins pipeline, we use SonarQube to report on our code coverage. After running all of our unit/integration tests to produce the .coverage file, we need to analyze this file to create the ".coverage.coveragexml" which is ultimately what is used by SonarQube to interpret the code coverage. We do this by using the CodeCoverage.exe:
"C:\Program Files (x86)\Microsoft Visual Studio\2022\TestAgent\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"{somePath}\{someName}.coverage.coveragexml" "{somePath}\{someName}.coverage"
This command appears to be working, but when you run dir /s *.coveragexml
(within the directory), it displays something like:
Directory of C:\jenkins\path\to\TestResults\coverageFile
03/22/2022 04:59 PM 64 ContainerAdministrator_DC420D3FA0BA_2022-03-22.16_46_43.coverage.coveragexml
1 File(s) 64 bytes
64 bytes is practically nothing - and I believe this is the reason why our SonarQube metrics show we have 0 coverage now.
I added the same dir
command, only this time to check for the .coverage
file(s), and those come back with only 10 bytes in them - making me think that these files are essentially empty. I saw this post that seems to be a similar issue. The accepted answer said to change the platform type from x86 to x64, but that did not work in my case.
The vstest.console command for running our tests is:
vstest.console /Parallel /EnableCodeCoverage /Logger:trx /Platform:x86 ".\somePath\Test.dll"
This issue originally started back when we made a change to our Jenkinsfile for it to use Visual Studio 2022 instead of 2019 (the base image was updated) in the command that started the CodeCoverage executable.
What could be causing the coverage files to be nearly/completely empty and how can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我们使用的基础映像必须具有代码覆盖工具的非企业版(这是一个 要求)。我们使用企业版工具在本地测试了 SonarQube 项目命令(我的计算机上安装了 Visual Studio 2022 Enterprise),生成的覆盖文件包含正确的数据。但是,当我们使用 Visual Studio Professional 安装时,文件是空的,就像我们的 Jenkins 管道一样。
如前所述,这种情况在基础映像更新时开始发生 - 特别是在 附近2021 年 11 月 8 日。看来我们正在使用的基本 docker 映像 (mcr.microsoft .com/dotnet/framework/sdk:4.8-20220210-windowsservercore-ltsc2019)有最新的2022年工具,但一定不是企业版本 - 因此是空文件。
我们将管道切换为使用 dotCover 来执行分析,效果很好正如预期,我们的 SonarQube 覆盖范围恢复正常。
It seems the base image we use must have a non-enterprise edition of the Code Coverage tools (which is a requirement). We tested our SonarQube projects commands locally using an enterprise edition of the tools (I have Visual Studio 2022 Enterprise installed on my machine), and the coverage files produced contain the correct data. However, when we used a Visual Studio Professional install, the files are empty just like our Jenkins pipeline.
As stated, this started happening when the base image was updated - in particular it was around November 8th 2021. It seems the base docker image we were using (mcr.microsoft.com/dotnet/framework/sdk:4.8-20220210-windowsservercore-ltsc2019) has the latest 2022 tools, but it must not be an enterprise edition - hence the empty files.
We switched our pipeline over to using dotCover instead to perform the analysis, which works as expected and our SonarQube coverage is back to normal.