蚂蚁,声纳 - 0%code覆盖 [英] Ant, Sonar - 0% code coverage
问题描述
我有蚂蚁声纳任务的问题。这个任务最终成功但不运行单元测试,并没有显示出code覆盖。
I have problem with ant sonar task. This task end with success but don't run unit tests and don't show code coverage.
测试任务。
<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 - 覆盖信息没有收集。或许你忘了,包括调试信息编译成类?
until sonar task runs i got a warning 10:00:20.290 WARN o.s.p.j.JaCoCoPlugin - Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
推荐答案
我会建议你:
-
使用最新版本的声纳Ant任务的(从我可以在脚本中看到,您使用的旧的语法)
use the latest version of the Sonar Ant Task (from what I can see in your script, you're using the old syntax)
看看我们的样例Ant项目来找出你的问题。最可能的是,下面的例子是你在找什么:<一href=\"https://github.com/SonarSource/sonar-examples/tree/master/projects/$c$c-coverage/ut/ant/ut-ant-jacoco-runTests\" rel=\"nofollow\">https://github.com/SonarSource/sonar-examples/tree/master/projects/$c$c-coverage/ut/ant/ut-ant-jacoco-runTests
take a look at our sample Ant projects to find out where your issue is. Most probably, the following example is what you're looking for: https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/ut/ant/ut-ant-jacoco-runTests
这篇关于蚂蚁,声纳 - 0%code覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!