我使用Sonar 4.1.1,JBoss6.x,Jacoco0.6.4,使用Ant执行任务--我不允许使用Maven。在eclipse工作区中,我有两个项目,一个是web应用程序,另一个是selenium测试。
我能够获得单元测试和代码覆盖的单元测试。但是声纳无法读取Jacoco创建的集成测试文件。我认为我创建jacoco-it.exec文件的方式可能有问题,所以声纳无法读取它。因为声纳确实读取了我的jacoco-ut.exec文件。而且我可以同时使用reportPath和itReportPath来读取我的jacoco-ut.exec文件,没有问题。同时也认为我的构建文件可能有问题。我做了很多研究,尝试了许多不同的方法来创建jacoco-it.exec文件,不同的jacoco设置,并遵循不同的例子,从声纳,射精,其他博客,但仍然不能工作。我一定是错过了什么帮助!!谢谢!!
我有如下支持Jboss的VM论据
-javaagent:/path to jar/jacocoagent.jar=destfile=/path for create/jacoco-it.exec当我运行selenium时,上面的代码使用一些数据创建一个文件,大小约为1.3MB
以下是与此问题相关的构建部分
<property name="sonar.sourceEncoding" value="UTF-8" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.jacoco.reportsPath" value="${reports.dir}/junit" />
<property name="sonar.jacoco.itReportPath" value="${reports.dir}/jacoco-it.exec" />
<property name="sonar.jacoco.reportPath" value="${reports.dir}/jacoco-ut.exec" />
<target name="unitTest" depends="compile">
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath>
<path refid="classpath"/>
</classpath>
</taskdef>
<!-- Import the JaCoCo Ant Task -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="classpath"/>
</taskdef>
<!-- Run your unit tests, adding the JaCoCo agent -->
<jacoco:coverage destfile="reports/jacoco-ut.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<junit printsummary="yes" haltonfailure="yes" forkmode="once" fork="true" dir="${basedir}" failureProperty="test.failed">
<classpath location="${classes.dir}" />
<classpath refid="classpath"/>
<formatter type="plain" />
<formatter type="xml" />
<batchtest fork="true" todir="${reports.junit.xml.dir}">
<fileset dir="src">
<include name="**/*TestAdd.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<target name="coverageTest" depends="compile">
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath>
<path refid="classpath"/>
</classpath>
</taskdef>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="classpath"/>
</taskdef>
<!--Run your unit tests, adding the JaCoCo agent-->
<jacoco:coverage xmlns:jacoco="antlib:org.jacoco.ant" dumponexit="true" >
<junit printsummary="yes" haltonfailure="yes" forkmode="once" fork="true" dir="${basedir}" failureProperty="test.failed">
<classpath location="${classes.dir}"/>
<classpath refid="classpath"/>
<formatter type="plain" />
<formatter type="xml" />
<formatter type="plain" usefile="false"/>
<batchtest todir="${reports.junit.xml.dir}">
<fileset dir="../HelloAppTest/src">
<include name="**/answerTest.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>发布于 2015-01-26 16:25:06
原因是,您可能没有将Jacocoagent.jar文件附加到“”(例如: JBoss / Tomcat) JVM的作用域并停止它,这样它就可以将最终的代码覆盖率数据刷新到它的exec文件中。
一旦您这样做(而不是使用Maven/ANT的JVM范围),运行您的非单元(IT)测试,然后停止目标JVM。
在目标JVM被停止后,您将得到最终的jacoco .exec文件,用于IT测试。对sonar.jacoco.itReportPath变量使用该文件,它就能工作了。
对于示例:我将这个变量传递给tomcat的startup.sh脚本,并在启动Tomcat(目标JVM)时,在Tomcat的实际启动命令中使用这个变量。
PROJ_EXTRA_JVM_OPTS=-javaagent:tomcat/jacocoagent.jar=destfile=build/jacoco/IT/jacocoIT.exec,append=falsehttps://stackoverflow.com/questions/22230159
复制相似问题