maven - No test coverage in sonar -


i have multimodule maven project. have 2 tests in it. tests run during build , sonarqube shows 100% tests (2) passed. coverage empty. why it? other simple maven project uploads coverage in sonarqube. made test in same way in both projects.

there more ways it, best way found use jacoco maven plugin, configure add it's agent surefire execution (and, optionally, if use integration tests, failsafe) , add these files sonarqube config.

a explanation i've found here. basic stuff quite (here surefire):

<plugin>     <groupid>org.jacoco</groupid>     <artifactid>jacoco-maven-plugin</artifactid>     <version>0.7.5.201505241946</version>     <executions>         <!--             prepares property pointing jacoco runtime agent             passed vm argument when maven surefire plugin executed.         -->         <execution>             <id>pre-unit-test</id>             <goals>                 <goal>prepare-agent</goal>             </goals>             <configuration>                 <!-- sets path file contains execution data. -->                 <destfile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destfile>                 <!--                     sets name of property containing settings                     jacoco runtime agent.                 -->                 <propertyname>surefireargline</propertyname>             </configuration>         </execution>         <!--             ensures code coverage report unit tests created after             unit tests have been run.         -->         <execution>             <id>post-unit-test</id>             <phase>test</phase>             <goals>                 <goal>report</goal>             </goals>             <configuration>                 <!-- sets path file contains execution data. -->                 <datafile>${project.build.directory}/coverage-reports/jacoco-ut.exec</datafile>                 <!-- sets output directory 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 vm argument line used when unit tests run. -->         <argline>${surefireargline}</argline>         <!-- skips unit tests if value of skip.unit.tests property true -->         <skiptests>${skip.unit.tests}</skiptests>      </configuration> </plugin> 

with can configure sonarqube (settings -> java) find jacoco unittest file @ /target/coverage-reports/jacoco-ut.exec, should enough coverage reliably when running sonar:sonar goal afterwards.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -