Coverages always are 0.

47 views
Skip to first unread message

Weisong Sun

unread,
Jul 3, 2019, 10:57:15 PM7/3/19
to JaCoCo and EclEmma Users

I execute the following command on my mac terminal, then I can get the file "jacoco.exec". I use Ant to extract report, but the coverages are always 0.

java -javaagent:/Users/sunweisong/Desktop/jacocoagent.jar=includes=net.mooctest.*,output=file,destfile=jacoco.exec
Thank you for your attenting my question.

structure.jpg


Marc Hoffmann

unread,
Jul 3, 2019, 11:58:31 PM7/3/19
to JaCoCo and EclEmma Users
Hi,

obviously your command line does not execute anything. There is no main class to be executed.

As a general rule we recommend to first make your test setup run, and then add code coverage to it. It it does not run without code coverage it will neither run with JaCoCo ;)

Regards,
-marc


<structure.jpg>



-- 
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/b102c9d5-4fa6-4bb9-8c51-b56fa783ef0a%40googlegroups.com.
<structure.jpg>

Weisong Sun

unread,
Jul 4, 2019, 1:19:06 AM7/4/19
to JaCoCo and EclEmma Users

<?xml version="1.0" ?>


<project xmlns:jacoco="antlib:org.jacoco.ant" name="Ant Build with JaCoCo" default="jacoco">


    <description>


        Ant is employed to extract the report from jacoco running results.


    </description>


    <property name="src.dir" location="src/main/java"/>


    <property name="result.dir" location="target"/>


    <property name="result.classes.dir" location="${result.dir}/classes"/>


    <property name="result.report.dir" location="${result.dir}/jacoco"/>


   

    <property name="result.exec.file" location="jacoco.exec"/>


    <property name="jacocoant.dir" location="/Users/sunweisong/Desktop/java resource/jacoco-0.8.4/lib/jacocoant.jar"/>


   


    <!--  Step 1: Import JaCoCo Ant tasks  -->


    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">


        <classpath path="${jacocoant.dir}" />


    </taskdef>


    <target name="jacoco">


        <delete dir="${result.report.dir}" />


        <mkdir dir="${result.report.dir}" />


        <jacoco:report>


            <!-- This task needs the collected execution data and ... -->


            <executiondata>


                <file file="${result.exec.file}" />


            </executiondata>


            <!--  the class files and optional source files ...  -->


            <structure name="JaCoCo Report">


                <classfiles>


                    <fileset dir="${result.classes.dir}" />


                </classfiles>


                <sourcefiles encoding="UTF-8">


                    <fileset dir="${src.dir}" />


                </sourcefiles>


            </structure>


            <!--  to produce reports in different formats.  -->


            <html destdir="${result.report.dir}"/>


            <csv destfile="${result.report.dir}/report.csv"/>


            <xml destfile="${result.report.dir}/report.xml"/>


        </jacoco:report>


    </target>


</project>


The above is my "build.xml" file, whether I need to add the configuration as like the following?
<target name="test" depends="compile">
<!--
Step 2: Wrap test execution with the JaCoCo coverage task
-->
<jacoco:coverage destfile="${result.exec.file}">
<java classname="org.jacoco.examples.parser.Main" fork="true">
<classpath path="${result.classes.dir}"/>
<arg value="2 * 3 + 4"/>
<arg value="2 + 3 * 4"/>
<arg value="(2 + 3) * 4"/>
<arg value="2 * 2 * 2 * 2"/>
<arg value="1 + 2 + 3 + 4"/>
<arg value="2 * 3 + 2 * 5"/>
</java>
</jacoco:coverage>
</target>



在 2019年7月4日星期四 UTC+8上午11:58:31,Marc R. Hoffmann写道:
Hi,

obviously your command line does not execute anything. There is no main class to be executed.

As a general rule we recommend to first make your test setup run, and then add code coverage to it. It it does not run without code coverage it will neither run with JaCoCo ;)

Regards,
-marc


On 4. Jul 2019, at 04:57, Weisong Sun <weison...@gmail.com> wrote:

I execute the following command on my mac terminal, then I can get the file "jacoco.exec". I use Ant to extract report, but the coverages are always 0.

java -javaagent:/Users/sunweisong/Desktop/jacocoagent.jar=includes=net.mooctest.*,output=file,destfile=jacoco.exec
Thank you for your attenting my question.

<structure.jpg>



-- 
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jac...@googlegroups.com.

Marc Hoffmann

unread,
Jul 4, 2019, 11:53:13 AM7/4/19
to JaCoCo and EclEmma Users
I can only reiterate my advice to proceed as follows:

1) Make your test setup run without code coverage
2) Add JaCoCo to it

In exact this sequence. Not the other way round.


To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/3a93f881-70d8-4f5d-ad1f-abc50aeefcb3%40googlegroups.com.

Evgeny Mandrikov

unread,
Jul 4, 2019, 12:25:23 PM7/4/19
to JaCoCo and EclEmma Users
Fully agree with Marc. In addition - there are already plenty of tutorials and examples in internet for both points, to learn about the first point (Apache Ant) there are even books. Have you tried to search? If not, then please try - right now using Google was able to easily find following tutorial for the first point - https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html and following book - https://www.manning.com/books/ant-in-action , and for the second point - http://javaworld-abhinav.blogspot.com/2014/06/automating-code-coverage-and-junit.html Please read.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe@googlegroups.com.

Weisong Sun

unread,
Jul 5, 2019, 1:47:41 AM7/5/19
to JaCoCo and EclEmma Users
Thank you for the explanation. I have understood it and addressed it.

在 2019年7月4日星期四 UTC+8下午11:53:13,Marc R. Hoffmann写道:
To unsubscribe from this group and stop receiving emails from it, send an email to jac...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/3a93f881-70d8-4f5d-ad1f-abc50aeefcb3%40googlegroups.com.

Weisong Sun

unread,
Jul 5, 2019, 1:49:56 AM7/5/19
to JaCoCo and EclEmma Users
Thank you for answering, and I have addressed it. :)

在 2019年7月5日星期五 UTC+8上午12:25:23,Evgeny Mandrikov写道:
To unsubscribe from this group and stop receiving emails from it, send an email to jac...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/3a93f881-70d8-4f5d-ad1f-abc50aeefcb3%40googlegroups.com.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages