SonarQube测试用例规则不会将@Test注释考虑在内 [英] SonarQube test case rule does not take @Test annotation into account with Eclipse
问题描述
我看到类似于此问题的问题。在Maven项目上运行 mvn sonar:sonar
作为Jenkins后期构建操作时,JUnit测试中的@Test和@Ignore注释被正确识别。当我通过SonarQube Eclipse插件在同一个项目上运行SonarQube预览时,注释是不被识别,并且显示了(错误的)主要的错误问题。
I am seeing an issue similar to this question. When running mvn sonar:sonar
as a Jenkins post-build action on a Maven project, @Test and @Ignore annotations in JUnit tests are recognized properly. When I run a SonarQube preview on the same project via the SonarQube Eclipse plugin, the annotations are not recognized and there are (erroneous) Major bug issues shown.
我遵循了安装和配置Eclipse插件的说明 here 和这里。我缺少配置吗?
I have followed the directions for installing and configuring the Eclipse plugin here and here. Am I missing configuration somewhere?
- SonarQube服务器5.1.2与Java插件3.4
- Eclipse Luna 4.4.0
- m2e 1.6.1.20150625
- SonarQube集成Eclipse 3.5.0.20150804-1512-RELEASE(4个功能)
- Apache Maven 3.2.2(用于Jenkins和Eclipse)
- SonarQube server 5.1.2 with Java plugin 3.4
- Eclipse Luna 4.4.0
- m2e 1.6.1.20150625
- SonarQube Integration for Eclipse 3.5.0.20150804-1512-RELEASE (4 features)
- Apache Maven 3.2.2 (for both Jenkins and Eclipse)
更新:
我的多模块项目的结构如下:
My multi-module project is structured like this:
Top level aggregator POM (is not the parent)
Project parent POM
Module 1 (extends project parent)
Module 2 (extends project parent)
当顶级目录被扩展时,没有Maven Dependencies子目录,因为顶级POM不包含任何依赖关系(只有一个模块
块)。我在顶级运行SonarQube分析,所以SonarQube Eclipse插件没有所需的依赖关系,我看到错误。如果我在一个单独的模块上运行分析,我只看到预期的错误,而不是额外的错误。
When the top level directory is expanded, there is no Maven Dependencies child directory, because the top level POM doesn't include any dependencies (only a modules
block). I was running the SonarQube analysis at the top level, so the SonarQube Eclipse plugin didn't have the dependencies needed, and I saw the errors. If I run the analysis on one of the individual modules, I see only the expected errors, not the extra ones.
推荐答案
问题通常是由于缺少测试类路径(丢失或不正确的sonar.java.test.libraries /二进制文件)引起的。由于 https://jira.sonarsource.com,更新到SQ Java插件3.5至少会隐藏问题/浏览/ SONARJAVA-1193 。
This issue is usually caused by missing test classpath (missing or bad sonar.java.test.libraries/binaries). Updating to SQ Java plugin 3.5 will at least hide the problem thanks to https://jira.sonarsource.com/browse/SONARJAVA-1193.
更新:
如果您使用的是m2e,导入多模块Maven项目,您应该每个Maven模块获得一个Eclipse项目。然后,您应该在每个叶子模块上运行SonarQube分析。
If you are using m2e, when importing a multi module Maven project you should get one Eclipse project per Maven module. And then you should run SonarQube analysis on each leaf modules.
这篇关于SonarQube测试用例规则不会将@Test注释考虑在内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!