我对蚂蚁声纳任务有问题。此任务以成功结束,但不运行单元测试,也不显示代码覆盖率。
测试任务
<target name="test" depends=".....">
<path id="classpath">
<fileset dir="test/lib" includes="**/*.jar"/>
<fileset dir="lib" includes="**/*.jar"/>
<pathelement location="......."/>
</path>
<mkdir dir="build/tests"/>
<javac srcdir="test/src" destdir="build/tests" includes="**/*.java" debug="${debug}" deprecation="${deprecation}" optimize="${optimize}" nowarn="${nowarn}" fork="true">
<classpath refid="classpath"/>
</javac>
<copy todir="build/tests">
<fileset dir="test/src" excludes="**/*.java"/>
</copy>
<jacoco:coverage destfile="target/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<junit printsummary="yes" fork="true" haltonfailure="false" showoutput="true" failureproperty="test.failed">
<formatter type="xml"/>
<classpath refid="classpath"/>
<classpath>
<pathelement location="build/tests"/>
</classpath>
<test name="com........MainTestSuite" todir="build"/>
</junit>
</jacoco:coverage>
<fail message="Test failure detected, check test results." if="test.failed"/>
</target>和声纳任务:
<target name="sonar" depends="build">
<property name="sonar.tests" value="test" />
<property name="sonar.libraries" value="" />
<property name="sonar.surefire.reportsPath" value="sonarWorkDir" />
<!-- The following properties are required to use JaCoCo: -->
<!-- 1. Tells Sonar to run the unit tests -->
<property name="sonar.dynamicAnalysis" value="true" />
<!-- 2. Tells Sonar which "tests" targets to run -->
<property name="sonar.jacoco.antTargets" value="test" />
<!-- 3. Tells Sonar to use JaCoCo as the code coverage engine -->
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<!-- Execute Sonar -->
<sonar:sonar key="${JOB_NAME}" version="${VERSION}" xmlns:sonar="antlib:org.sonar.ant">
<sources>
<path location="...../src" />
</sources>
<binaries>
<path location="build/....." />
</binaries>
</sonar:sonar>
</target>在声纳任务运行之前,我收到警告10:00:20.290 WARN o.s.p.j.JaCoCoPlugin - Coverage信息未收集。也许您忘记在编译后的类中包含调试信息?
发布于 2013-01-08 17:38:22
我建议你:
发布于 2014-02-26 02:17:08
有点晚了,但我最近遇到了这个问题,在互联网上找不到简单的解决方案。相反,为了解决这个问题,我简单地采纳了堆栈跟踪的建议。Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
然后返回到我的ant文件,确保源文件(而不是test)是在调试模式下编译的。显然,jacoco插件需要额外的信息,比如行号,以便计算代码覆盖率。更改ant文件后,您最终应该会在声纳中看到代码覆盖率百分比。
<javac srcdir="${source.dir}" target="1.6" source="1.6" destdir="${build.classes.dir}" debug="on">
...
</javac>此外,请确保包括以下声纳属性:
sonar.binaries=build/classes
sonar.tests=junit/tests
sonar.dynamicAnalysis=reuseReports
sonar.junit.reportsPath=build/test-reports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=build/test-reports/jacoco.exec因此您可能希望删除sonar.antTargets并将sonar.dynamicAnalysis值更改为reuseReports
https://stackoverflow.com/questions/14211584
复制相似问题