使用声纳和jacoco进行手动回归的代码覆盖率

时间:2015-12-13 12:08:42

标签: ant sonarqube jacoco

我正在尝试为使用jacoco和sonar进行手动测试的webapp生成代码覆盖率。

我可以通过以下方式修改catalina.bat来生成jacoco.exec文件:

SET JACOCO=-javaagent:\jacoco-0.7.5.201505241946\lib\jacocoagent.jar=destfile=C:\jacoco.exec,append=true,includes=* set JAVA_OPTS=%JAVA_OPTS% %JACOCO% 然后我将jacoco.exec文件复制到sonarcube内的目标文件夹并运行ant sonar。 build.xml包含以下条目:

    <!-- The following properties are required to use JaCoCo: -->
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath" value="target/jacoco.exec" />

<!-- Define the SonarQube target -->
<target name="sonar">

    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
            <!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
            <classpath path="../apache-ant-1.9.6/lib/sonar-ant-task-2.3.jar"/>
    </taskdef> 
        <!-- Execute the SonarQube analysis -->
        <sonar:sonar/>

</target>

</project>

如果跟随,我从蚂蚁得到的输出。我没有在网址上看到报告中的任何报道 http://localhost:9000/dashboard/index/org.codehaus.sonar:example-java-ant

我错过了什么吗?

c:\sonarqube>ant sonar
Buildfile: c:\sonarqube\build.xml

sonar:
[sonar:sonar] Apache Ant(TM) version 1.9.6 compiled on June 29 2015
[sonar:sonar] SonarQube Ant Task version: 2.3
[sonar:sonar] Loaded from: file:/C:/apache-ant-1.9.6/lib/sonar-ant-task-2.3.jar
[sonar:sonar] INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
[sonar:sonar] INFO: Work directory: c:\sonarqube\.sonar
[sonar:sonar] INFO: SonarQube Server 5.2
[sonar:sonar] 17:18:52.370 INFO  - Load global repositories
[sonar:sonar] 17:18:52.959 INFO  - Load global repositories (done) | time=588ms
[sonar:sonar] 17:18:53.034 INFO  - User cache: C:\Users\Administrator\.sonar\cache
[sonar:sonar] 17:18:53.932 INFO  - Load plugins index
[sonar:sonar] 17:18:53.952 INFO  - Load plugins index (done) | time=20ms
[sonar:sonar] 17:18:54.677 INFO  - Process project properties
[sonar:sonar] 17:18:57.381 INFO  - Load project repositories
[sonar:sonar] 17:18:57.493 INFO  - Load project repositories (done) | time=112ms
[sonar:sonar] 17:18:57.535 INFO  - Apply project exclusions
[sonar:sonar] 17:18:57.667 INFO  - Load quality profiles
[sonar:sonar] 17:18:57.983 INFO  - Load quality profiles (done) | time=315ms
[sonar:sonar] 17:18:58.039 INFO  - Load active rules
[sonar:sonar] 17:19:00.610 INFO  - Load active rules (done) | time=2571ms
[sonar:sonar] 17:19:00.636 WARN  - 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[sonar:sonar] 17:19:00.797 WARN  - SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.
scm.provider to define SCM of your project.
[sonar:sonar] 17:19:00.800 INFO  - Publish mode
[sonar:sonar] 17:19:00.805 INFO  - -------------  Scan Simple Java Project analyzed with the SonarQube Ant Task
[sonar:sonar] 17:19:01.844 INFO  - Language is forced to java
[sonar:sonar] 17:19:01.887 INFO  - Load server rules
[sonar:sonar] 17:19:02.373 INFO  - Load server rules (done) | time=486ms
[sonar:sonar] 17:19:02.755 INFO  - Base dir: c:\sonarqube
[sonar:sonar] 17:19:02.756 INFO  - Working dir: c:\sonarqube\.sonar
[sonar:sonar] 17:19:02.781 INFO  - Source paths: src
[sonar:sonar] 17:19:02.786 INFO  - Source encoding: windows-1252, default locale: en_US
[sonar:sonar] 17:19:02.787 INFO  - Index files
[sonar:sonar] 17:19:02.854 INFO  - 0 files indexed
[sonar:sonar] 17:19:02.857 INFO  - Quality profile for java: Sonar way
[sonar:sonar] 17:19:02.999 INFO  - Sensor Lines Sensor
[sonar:sonar] 17:19:03.005 INFO  - Sensor Lines Sensor (done) | time=6ms
[sonar:sonar] 17:19:03.006 INFO  - Sensor QProfileSensor
[sonar:sonar] 17:19:03.095 INFO  - Sensor QProfileSensor (done) | time=89ms
[sonar:sonar] 17:19:03.096 INFO  - Sensor SCM Sensor
[sonar:sonar] 17:19:03.097 INFO  - No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
[sonar:sonar] 17:19:03.100 INFO  - Sensor SCM Sensor (done) | time=4ms
[sonar:sonar] 17:19:03.100 INFO  - Sensor Code Colorizer Sensor
[sonar:sonar] 17:19:03.106 INFO  - Sensor Code Colorizer Sensor (done) | time=6ms
[sonar:sonar] 17:19:03.107 INFO  - Sensor CPD Sensor
[sonar:sonar] 17:19:03.108 INFO  - JavaCpdEngine is used for java
[sonar:sonar] 17:19:03.110 INFO  - Sensor CPD Sensor (done) | time=3ms
[sonar:sonar] 17:19:03.304 INFO  - Analysis reports generated in 192ms, dir size=5 KB
[sonar:sonar] 17:19:03.320 INFO  - Analysis reports compressed in 15ms, zip size=2 KB
[sonar:sonar] 17:19:03.758 INFO  - Analysis reports sent to server in 424ms
[sonar:sonar] 17:19:03.762 INFO  - ANALYSIS SUCCESSFUL, you can browse 

1 个答案:

答案 0 :(得分:0)

查看分析日志,我们看不到任何执行的JaCoCo传感器。 JaCoCo传感器仅在您的分析中包含java文件时执行,而您在日志中的每个0 files indexed行都没有这样做。

要解释这种行为,您必须了解JaCoCo传感器仅报告索引文件的覆盖范围,因此如果没有java文件,则没有必要执行它。

因此,要报告和计算覆盖率,您必须导入与您在项目中分析的某些源文件相关的覆盖率报告。