【发布时间】:2014-04-09 10:10:19
【问题描述】:
我使用 Sonar 4.1.1、Jboss 6.x、Jacoco 0.6.4,用 Ant 执行任务我不允许使用 Maven。在一个 Eclipse 工作区中,我有两个项目,一个是 web 应用程序,另一个是 selenium 测试。
我能够获得单元测试的单元测试和代码覆盖率。但声纳无法读取Jacoco 创建的集成测试文件。我认为我创建jacoco-it.exec 文件的方式可能有问题,因此声纳无法读取它。因为声纳确实读取了我的jacoco-ut.exec 文件。我可以同时拥有reportPath 和itReportPath 来毫无问题地读取我的jacoco-ut.exec 文件。还认为我的构建文件中可能有问题。我做了很多研究并尝试了许多不同的方法来创建jacoco-it.exec 文件、不同的 Jacoco 设置,并遵循了来自 sonar、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>
【问题讨论】:
标签: selenium ant jboss6.x sonarqube jacoco