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

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

问题描述

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

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天全站免登陆