У меня есть проект мультимодуля maven. У меня есть 2 теста. Тесты, выполняемые во время сборки и сонарквиста, показывают, что 100% тестов (2) прошли. Но охват пуст. Почему это? Мой другой простой проект maven успешно загружает покрытие в sonarqube. Я сделал тест таким же образом в обоих проектах.Нет испытательного покрытия в сонаре
0
A
ответ
1
Есть, вероятно, больше способов сделать это, но лучший способ, который я нашел, - использовать плагин Jacoco maven, настроить его для добавления его агента в выполнение Surefire (и, при необходимости, если вы используете тесты интеграции, Failsafe) а затем добавьте эти файлы в конфигурацию SonarQube.
Хорошее объяснение для этого я нашел here. Основной материал довольно просто (здесь только для безошибочного):
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
</plugin>
При том, что вы можете настроить SonarQube (Настройки -> Java), чтобы найти jacoco UnitTest файл в /target/coverage-reports/jacoco-ut.exec
, который должен быть достаточно, чтобы получить покрытие надежно при запуске цели sonar:sonar
.
Просьба представить более подробную информацию, вашу конфигурацию, версию sonarqube. Как вы рассчитали свой охват? – TimStefanHauschildt