sonarqube - 如何让sonarqube忽略等号和哈希码

标签 sonarqube test-coverage

我想知道目前是否可以忽略 Sonar 测​​试覆盖的 equals 和 hashcode 方法?我听说过 block 排除,但它没有用。

最佳答案

(假设您使用 jacoco 进行覆盖率报告)

如果您不使用 Lombok,您可以尝试将 @Generated 注释添加到您想要跳过的方法中。我不确定这是否有效——但值得一试!

如果您[像我一样]使用 Lombok,这里有一个来自 Rainer Hahnekamp 的解决方案,它将代码标记为@Generated,这使得 jacoco 忽略这些方法,进而使 sonarqube 显示更高的覆盖率。

Luckily, beginning with version 0.8.0, Jacoco can detect, identify, and ignore Lombok-generated code. The only thing you as the developer have to do is to create a file named lombok.config in your directory’s root and set the following flag:

lombok.addLombokGeneratedAnnotation = true

This adds the annotation lombok.@Generated to the relevant methods, classes and fields. Jacoco is aware of this annotation and will ignore that annotated code.

Please keep in mind that you require at least version 0.8.0 of Jacoco and v1.16.14 of Lombok.

https://www.rainerhahnekamp.com/en/ignoring-lombok-code-in-jacoco/

关于sonarqube - 如何让sonarqube忽略等号和哈希码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47923297/

相关文章:

C 的代码覆盖率

unit-testing - 没有 Sonar 报告单元测试成功

unit-testing - Jacoco 检查与 jacoco 报告中的不同覆盖率值

reactjs - 无法在 Windows 10 中使用 react 测试库生成 react 测试覆盖率

c# - 尝试在Docker管道中生成测试覆盖率时在 “No report files specified”中运行(Linux)

jestjs - jest@23.1.0 collectCoverageFrom 不选择根目录外的文件

authentication - 忘记了 sonarqube 密码。在本地使用它,没有数据库

java - Package By Feature 和 SONAR 表示依赖循环

java - Sonarqube - 包含物被忽略

javascript - 如何告诉 Sonar 使用我的 surefire 报告作为单元测试结果