如何强制代码覆盖率为零? [英] How to force code coverage to Zero?

查看:27
本文介绍了如何强制代码覆盖率为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个没有单元测试用例的 java 项目.当我尝试使用 SonarQube 分析这些项目时,我无法获得单元测试代码覆盖率,因为它没有任何测试用例.根据我的研究,我发现如果没有单元测试用例,我可以强制它显示为零.官方 Jacoco Java 文档提到 sonar.jacoco.reportMissing.force.zero=true.

I have several java projects with no unit test cases. When I try to analyse these projects using SonarQube I am unable to get unit test code coverage because it doesn't have any test cases. As per my research I saw that I can force it to show it as zero if there are no unit test cases. The official Jacoco Java documentation mentions sonar.jacoco.reportMissing.force.zero=true.

我的 SonarQube 分析将使用 maven 构建和 SonarQube 5.6.6 和 sonar-java 4.11.0.10660 完成.

My SonarQube analysis will be done using maven builds and SonarQube 5.6.6 and sonar-java 4.11.0.10660.

如何在 maven 中设置此参数,以便在我的覆盖范围内显示为零单元测试用例?

How can I set this parameter in maven so that it can show as zero unit test cases in my coverage?

推荐答案

从 6.2 版开始,SonarQube 会在分析器支持行为的情况下自动执行此操作.在该版本之前,该功能的可用性参差不齐且不完全可靠.为获得最佳效果,您应该升级 SonarQube.

From version 6.2 SonarQube does this automatically where the behavior is supported by the analyzers. Before that version, availability of the feature is spotty and not entirely reliable. For best results you should upgrade SonarQube.

也就是说,您可以像这样在分析命令行上设置该属性:

That said, you can set that property on the analysis command line like so:

mvn sonar:sonar -Dsonar.jacoco.reportMissing.force.zero=true

或者通过在你的 pom 中设置一个属性,如 显示在文档中

Or by setting a property in your pom, as shown in the docs

2019 年 12 月 16 日更新
大多数语言分析器现在计算 可执行行,因此覆盖报告中省略了文件无论如何都包含在计算中.但这只有在您提供覆盖率报告时才会生效.没有覆盖率报告 -> 根本没有覆盖率指标.

Update 16 Dec 2019
Most language analyzers now calculate Executable Lines, so files omitted from the coverage report are included in calculations anyway. But that only kicks in if you provide coverage reports. No coverage reports -> no coverage metrics at all.

这篇关于如何强制代码覆盖率为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆