缺少6.3的测试文件的SonarQube指标

时间:2017-06-01 17:37:48

标签: sonarqube

在多模块Maven项目中使用SonarQube 6.3,sonar-maven-plugin 3.3.0.660,Java 8。

在源文件上,代码覆盖率(使用JaCoCo)运行良好,分析插件,重复检测,测试执行和持续时间等也是如此。但是,我们没有测试文件的指标。这些文件被加载到SonarQube中,但是代码行和重复行是空白的(因为Coverage但是那个有意义),而Bugs,Vulnerabilities和Code Smells都是0.我们可能有错误配置,但我可以&#39 ;弄清楚是什么。

示例:一个模块包含Java和XML源代码和测试文件。 POM中的声纳属性是:

<sonar.sources>.</sonar.sources>
<sonar.inclusions>src/main/**/*,src/app/**/*,**/*.xml,**/*.properties,**/*.json</sonar.inclusions>
<sonar.tests>.</sonar.tests>
<sonar.test.inclusions>src/test/**/*,e2e/**/*</sonar.test.inclusions>

在SonarQube中 - &gt;管理 - &gt;分析范围,我们启用了导入未知文件。我们还将属性sonar.global.exclusions设置为target/**/*

使用Maven插件运行分析时,我们会在日志中看到这样的消息:

[INFO] 13:01:35.726 Base dir: /JENKINS_WS/project/module
[INFO] 13:01:35.726 Working dir: /JENKINS_WS/project/module/target/sonar
[INFO] 13:01:35.726 Source paths: .
[INFO] 13:01:35.726 Test paths: .
[INFO] 13:01:35.726 Source encoding: UTF-8, default locale: en_US
[INFO] 13:01:35.726 Index files
[INFO] 13:01:35.726 Included sources: 
[INFO] 13:01:35.726   src/main/**/*
[INFO] 13:01:35.726   src/app/**/*
[INFO] 13:01:35.726   **/*.xml
[INFO] 13:01:35.726   **/*.properties
[INFO] 13:01:35.727   **/*.json
[INFO] 13:01:35.727 Excluded sources: 
[INFO] 13:01:35.727   target/**/*
[INFO] 13:01:35.727   src/test/**/*
[INFO] 13:01:35.727   e2e/**/*
[INFO] 13:01:35.727 Included tests: 
[INFO] 13:01:35.727   src/test/**/*
[INFO] 13:01:35.727   e2e/**/*
...

测试目录中的文件似乎正在被正确索引:

[DEBUG] 13:01:35.778 'src/test/resources/log4j.xml' indexed as test with language 'xml'
[DEBUG] 13:01:35.779 'src/test/resources/appContext-test.xml' indexed as test with language 'xml'
[DEBUG] 13:01:35.779 'src/test/java/com/company/module/EnvEchoTest.java' indexed as test with language 'java'

Java扫描程序报告也分析了单个测试文件:

[INFO] 13:01:38.520 Java Test Files AST scan
[INFO] 13:01:38.520 1 source files to be analyzed
[DEBUG] 13:01:38.521 'src/test/java/com/company/module/EnvEchoTest.java' generated metadata as test  with charset 'UTF-8'
[DEBUG] 13:01:38.529 ----- Classpath analyzed by Squid:
[DEBUG] 13:01:38.529 /JENKINS_WS/project/module/target/test-classes
[DEBUG] 13:01:38.529 /JENKINS_WS/project/module/target/classes
... snip printing all the jar file debug msgs ....
[INFO] 13:01:38.567 1/1 source files have been analyzed
[INFO] 13:01:38.567 Java Test Files AST scan (done) | time=47ms

但是SonarQube中没有填充指标。任何人都可以提供指针吗?

1 个答案:

答案 0 :(得分:2)

一切都很好。或者至少按设计工作。

SonarQube旨在报告代码的质量,而且测试并不是真正的代码。他们是......支持文件。

也就是说,有a set of rules专门用于检查测试作为测试的质量。如果包含在您的个人资料中,则可能会引发测试问题。但是,所谓的正常规则不会针对测试运行,并且不会计算指标。

如果您真的想要这些东西,您需要对项目进行单独的第二次分析,其中sonar.sources属性指向测试目录。