I am running Java Sonar code analysis on an RHEL6 machine using Ant. To analyze integration integration, I use the JaCoCo plugin for sonar. I have a plugin in my library class. When I run the Selenium tests, the file "jacoco.exec" is generated (about 1 MB for 10 tests). Then I activate the Jacoco plugin in my Sonar Ant program and import it into Sonar. Sonar analysis logs say that the Jacoco file was analyzed (took about 5000 ms). However, the My Sonar IT widget displays 0% code coverage. I successfully got unit test code coverage with Cobertura.
My test goal:
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"> <classpath path="${buildHome}/libs/jacocoant.jar"/> </taskdef> <jacoco:coverage xmlns:jacoco="antlib:org.jacoco.ant"> <junit fork="yes" failureproperty="true" forkmode="once" maxmemory="1024m"> <formatter type="xml" /> <classpath refid="buildClasspath" /> <test name="${testName}" todir="${testLogs}" if="testcase" /> <batchtest haltonerror="false" todir="${testLogs}"> <fileset dir="${SeleniumScripts"> <include name="**/*.java" /> </fileset> </batchtest> </junit> </jacoco:coverage>
My Sonar Ant target:
... <property name="sonar.sources" value="${srcCode" /> <property name="sonar.tests" value="${testCode}" /> <property name="sonar.binaries" value="${srcAndTestBinaries}" /> <property name="sonar.dynamicAnalysis" value="reuseReports"/> <property name="sonar.surefire.reportsPath" value="${reportsPath}" /> <property name="sonar.core.codeCoveragePlugin" value="jacoco" /> <property name="sonar.jacoco.itReportPath" value="${jacocoCoveragePath}/jacoco.exec" /> <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"> <classpath path="${antLibPath}/sonar-ant-task-1.4.jar" /> </taskdef> <sonar:sonar key="projectKey" version="1.0" xmlns:sonar="antlib:org.sonar.ant"/>
I tried to include only the βrelevantβ things. I'm not sure that the jacoco: coverage element is the root element for Selenium tests, but it mentions "agent" in the execution logs, so I assume that the agent is used here as a proxy server also in the Java virtual machine.
I'm stuck, help :)
Update Here is part of Sonar's release:
[sonar:sonar] 08:36:15.619 INFO p.PhasesTimeProfiler - Sensor JaCoCoItSensor... [sonar:sonar] 08:36:15.623 INFO ospjJaCoCoPlugin - Analysing [file path omitted]\jacoco.exec [sonar:sonar] 08:36:17.272 INFO p.PhasesTimeProfiler - Sensor JaCoCoItSensor done: 1653 ms
source share