Sonar IT using JaCoCo givess 0% code coverage

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" /> <!-- Add the Sonar task --> <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 
+6
source share
2 answers

I may miss him, but I don’t see where you tell the agent where to store the results.

In my ant script, I have this:

  <jacoco:coverage enabled="${my.coverage.enabled}" destfile="${test.log.dir}/jacoco.exec"> 

completion of the junit task. Try defining destfile="${jacocoCoveragePath}/jacoco.exec" and see if it fixes this.

0
source

Hi, I am also involved in creating code coverage for an acceptance test using jacoco. For unit test, I use cobertura, and I can see the code coverage and unit test report in the sonar panel.

Now it will come to receive the code for the acceptance test. We conduct acceptance tests using selenium. I am wondering how jacoco generates code coverage for an acceptance test that runs using selenium.

From my guess, I think you should specify the path for jacocoagent.jar instead of jacocoant.jar. I am also mistaken. If you found a way to generate code coverage for a test that runs on selenium, you could provide a solution

0
source

All Articles