【发布时间】:2015-02-02 12:17:50
【问题描述】:
我正在使用 JaCoCo 进行代码覆盖。单元测试报告使用 junit 创建并正确导入,以便正确显示单元测试信息。 问题 是,我收到错误消息: 没有关于每个测试覆盖率的信息。并且代码覆盖率显示单元测试、集成测试和整体覆盖率的值为 0%。 我检查了 sonar-project.properties 中的所有必需信息,例如二进制、src、测试等。
我正在使用:
- SonarQube 4.5.1
- SonarRunner 2.4
- MySQL
- junit 4.1.1
- jacoco 0.7.2
jacoco.exec 位于项目基目录的 /target 文件中。
您可以在下面看到 sonar-project.properties: 从我的角度来看,所有必要的路径都已正确设置。 (即二进制、src、测试)
Comma-separated paths to directories with sources (required)
sonar.sources=src
compiled code
sonar.java.binaries=class
source code of unit tests
sonar.tests=test/src
Comma-separated paths to files with third-party libraries (JAR files in the case of Java)
sonar.java.libraries=jar
Language
sonar.language=java
Encoding of the source files
sonar.sourceEncoding=UTF-8
Additional parameters
sonar.my.property=value
Set Project Base
sonar.projectBaseDir=C:/snapshots/steffen_latest/software/java
Tells SonarQube to reuse existing reports for unit tests execution and coverage reports
sonar.dynamicAnalysis=reuseReports
JUnit path
sonar.surefire.reportsPath=test/report/junit
Tells SonarQube where the unit tests execution reports are
sonar.junit.reportsPath=test/report/junit
Tells SonarQube that the code coverage tool by unit tests is JaCoCo
sonar.java.coveragePlugin=jacoco
Import JaCoCo code coverage report.
Tells SonarQube where the unit tests code coverage report is
Unit Tests Coverage
sonar.jacoco.reportPath=target/jacoco.exec
Tells SonarQube where the integration tests code coverage report is
sonar.jacoco.itReportPath=target/it-jacoco.exec
这是来自 sonar-runner 的日志文件:
13:56:05.883 INFO - Sensor SurefireSensor...
13:56:05.883 INFO - parsing C:\work\snapshots\steffen_latest\software\java\test\report\junit
13:56:06.149 INFO - Sensor SurefireSensor done: 266 ms
13:56:06.149 INFO - Sensor JaCoCoItSensor...
13:56:06.195 INFO - Analysing C:\work\snapshots\steffen_latest\software\java\target\it-jacoco.exec
13:56:06.726 INFO - **No information about coverage per test**.
13:56:06.726 INFO - Sensor JaCoCoItSensor done: 577 ms
13:56:06.726 INFO - Sensor JaCoCoOverallSensor...
13:56:06.851 INFO - Analysing C:\work\snapshots\steffen_latest\software\java\.sonar\jacoco-overall.exec
13:56:07.178 INFO - **No information about coverage per test**.
13:56:07.178 INFO - Sensor JaCoCoOverallSensor done: 452 ms
13:56:07.178 INFO - Sensor JaCoCoSensor...
13:56:07.209 INFO - Analysing C:\work\snapshots\steffen_latest\or_base\software\java\target\jacoco.exec
13:56:07.521 INFO - **No information about coverage per test**.
13:56:07.521 INFO - Sensor JaCoCoSensor done: 343 ms
13:56:07.521 INFO - Sensor CPD Sensor (wrapped)...
13:56:07.521 INFO - JavaCpdEngine is used for java
13:56:07.521 INFO - Cross-project analysis disabled
13:56:09.019 INFO - Sensor CPD Sensor (wrapped) done: 1498 ms
13:56:09.144 INFO - Execute decorators...
13:56:16.166 INFO - Store results in database
谁能给我一个建议可能是什么问题? 因为不知道是什么问题... 几天以来我一直在研究这个问题,我真的不知道该怎么办..
提前谢谢你。
【问题讨论】:
-
每次测试的覆盖率是覆盖率之上的信息。每个测试的覆盖率是关于哪个测试覆盖了哪个文件的信息。 (而覆盖率只通知您测试覆盖了哪些行)。因此,请根据该信息澄清您的问题,因为“没有关于每次测试覆盖率的信息。”消息仅告诉我们您没有使用任何侦听器在每次测试之间转储 jacoco 会话。
-
感谢您的提示。问题是我们没有使用任何监听器在每次测试之间转储 jacoco 会话。
-
有机会发布您是如何配置的吗?我有同样的问题
-
@Stelos10 请发布您如何配置侦听器以在每次测试之间转储 jacoco 会话...
-
要获得
coverage per testSonar documentation 指向一个示例项目,他们在其中使用 Maven 配置文件来启用特殊的 JUnit 侦听器来启用此功能。检查here。