我有“TEST – *.xml”格式的JUnit测试报告,我正在尝试使用Ant将这些报告上传到SonarQube.我在build.xml文件中添加了以下属性,其中${reports.dir}计算到报告目录路径:
<property name="sonar.dynamicAnalysis" value="reuseReports"/>
<property name="sonar.junit.reportsPath" value="${reports.dir}"/>
以下是Ant任务的输出(某些信息已编辑):
sonar:
[sonar:sonar] Apache Ant(TM) version 1.9.3 compiled on December 23 2013
[sonar:sonar] Sonar Ant Task version: 2.1
[sonar:sonar] Loaded from: file:/C:/Program%20Files/Apache%20Ant/apache-ant-1.9.3-
bin/apache-ant-1.9.3/lib/sonar-ant-task-2.1.jar
[sonar:sonar] INFO: Default locale: "en_IE", source code encoding: "windows-1252"
(analysis is platform dependent)
[sonar:sonar] INFO: Work directory: C:\Users\Administrator\Desktop\.sonar
[sonar:sonar] INFO: Sonar Server 3.7.3
[sonar:sonar] 20:53:00.626 INFO - Load batch settings
[sonar:sonar] 20:53:00.689 INFO - User cache: C:\Users\Administrator\.sonar\cache
[sonar:sonar] 20:53:00.689 INFO - Install plugins
[sonar:sonar] 20:53:03.356 INFO - Install JDBC driver
[sonar:sonar] 20:53:03.356 INFO - Create JDBC datasource for
jdbc:mysql://<REDACTED>:3306/sonar?useUnicode=true&
characterEncoding=utf-8
[sonar:sonar] 20:53:04.916 INFO - Initializing Hibernate
[sonar:sonar] 20:53:09.986 INFO - Load project settings
[sonar:sonar] 20:53:10.033 INFO - Apply project exclusions
[sonar:sonar] 20:53:10.283 INFO - ------------- Scan <REDACTED>
[sonar:sonar] 20:53:10.283 INFO - Load module settings
[sonar:sonar] 20:53:11.250 INFO - Quality profile : [name=Sonar way,language=java]
[sonar:sonar] 20:53:11.265 INFO - Excluded tests:
[sonar:sonar] 20:53:11.265 INFO - **/package-info.java
[sonar:sonar] 20:53:11.359 INFO - Configure Maven plugins
[sonar:sonar] 20:53:11.499 INFO - Compare to previous analysis (2014-04-05)
[sonar:sonar] 20:53:11.546 INFO - Compare over 30 days (2014-03-06, analysis of
2014-04-05 20:09:46.0)
[sonar:sonar] 20:53:11.624 INFO - Compare to previous version
[sonar:sonar] 20:53:11.843 INFO - Base dir: C:\Users\Administrator\Desktop
[sonar:sonar] 20:53:11.843 INFO - Working dir: C:\Users\Administrator\Desktop\.sonar
[sonar:sonar] 20:53:11.843 INFO - Source encoding: windows-1252, default locale: en_IE
[sonar:sonar] 20:53:11.858 INFO - Sensor JavaSourceImporter...
[sonar:sonar] 20:53:11.858 INFO - Sensor JavaSourceImporter done: 0 ms
[sonar:sonar] 20:53:11.858 INFO - Sensor JavaSquidSensor...
[sonar:sonar] 20:53:11.858 INFO - Sensor JavaSquidSensor done: 0 ms
[sonar:sonar] 20:53:11.858 INFO - Sensor SurefireSensor...
[sonar:sonar] 20:53:11.858 INFO - parsing C:\Users\Administrator\Desktop\TestResults
[sonar:sonar] 20:53:11.952 INFO - Sensor SurefireSensor done: 94 ms
[sonar:sonar] 20:53:11.952 INFO - Sensor CpdSensor...
[sonar:sonar] 20:53:11.952 INFO - SonarEngine is used
[sonar:sonar] 20:53:11.952 INFO - Sensor CpdSensor done: 0 ms
[sonar:sonar] 20:53:11.952 INFO - Sensor InitialOpenIssuesSensor...
[sonar:sonar] 20:53:11.952 INFO - Sensor InitialOpenIssuesSensor done: 0 ms
[sonar:sonar] 20:53:11.952 INFO - Sensor ProfileSensor...
[sonar:sonar] 20:53:12.404 INFO - Sensor ProfileSensor done: 452 ms
[sonar:sonar] 20:53:12.404 INFO - Sensor ProfileEventsSensor...
[sonar:sonar] 20:53:12.420 INFO - Sensor ProfileEventsSensor done: 16 ms
[sonar:sonar] 20:53:12.420 INFO - Sensor ProjectLinksSensor...
[sonar:sonar] 20:53:12.451 INFO - Sensor ProjectLinksSensor done: 31 ms
[sonar:sonar] 20:53:12.451 INFO - Sensor VersionEventsSensor...
[sonar:sonar] 20:53:12.451 INFO - Sensor VersionEventsSensor done: 0 ms
[sonar:sonar] 20:53:12.451 INFO - Sensor JaCoCoSensor...
[sonar:sonar] 20:53:12.451 INFO - Project coverage is set to 0% since there is no
directories with classes.
[sonar:sonar] 20:53:12.451 INFO - Sensor JaCoCoSensor done: 0 ms
[sonar:sonar] 20:53:12.794 INFO - Execute decorators...
[sonar:sonar] 20:53:13.106 INFO - Store results in database
[sonar:sonar] 20:53:13.184 INFO - ANALYSIS SUCCESSFUL, you can browse <REDACTED>
[sonar:sonar] 20:53:13.231 INFO - Executing post-job class
org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob
[sonar:sonar] 20:53:13.231 INFO - Executing post-job class
org.sonar.plugins.core.batch.IndexProjectPostJob
[sonar:sonar] 20:53:13.293 INFO - Executing post-job class
org.sonar.plugins.dbcleaner.ProjectPurgePostJob
[sonar:sonar] 20:53:13.309 INFO - -> Keep one snapshot per day between 2014-03-08 and
2014-04-04
[sonar:sonar] 20:53:13.309 INFO - -> Keep one snapshot per week between 2013-04-06
and 2014-03-08
[sonar:sonar] 20:53:13.309 INFO - -> Keep one snapshot per month between 2009-04-11
and 2013-04-06
[sonar:sonar] 20:53:13.309 INFO - -> Delete data prior to: 2009-04-11
[sonar:sonar] 20:53:13.309 INFO - -> Clean <REDACTED> [id=12]
[sonar:sonar] 20:53:13.325 INFO - <- Clean snapshot 21
BUILD SUCCESSFUL
Total time: 17 seconds
我不知道为什么SonarQube告诉我没有JUnit测试.据我所知,Ant任务是成功的(所以他们上传了,对吧?).任何的想法?
解决方法:
添加指向包含测试的目录的属性sonar.tests.
该物业看起来像
<property name="sonar.tests" value="${tests.dir}"/>
你可以在这里找到文档.
https://docs.sonarqube.org/display/SONAR/Analysis+Parameters