Search code examples
antcode-coverageemmajacoco

JaCoCo report looks correct but can not view source


I am new to JaCoCo and trying to figure out why the html report that I am generating is not linked with my source.

The coverage numbers look correct and I can browse down to each class and then each method but I can not see the source. I have tried many different things inside the sourcefiles tag but nothing is working. Has anyone else had this issue? Here is a snippet of my ant script:

...

   <test name="test.fw.UITestSuite" todir="${logdir}"/>
    </junit>
    </jacoco:coverage>
    <fail if="TestFailed" status="1" message="UI junit test failure detected"/>
    <echo message="${src}"/>
    <jacoco:report>                                
        <executiondata>
            <file file="jacoco.exec"/>
        </executiondata>                            
        <structure name="UI">
            <classfiles>
                <fileset dir="${build}/fw"/>
            </classfiles>
            <sourcefiles encoding="UTF-8">
                <fileset dir="fw" includes="**./*.java"/>
            </sourcefiles>
        </structure>                                
        <html destdir="report"/>                                
    </jacoco:report>
</target>

...


Solution

  • Your fileset definition seems odd.

    The include must be (the first . is misplaced):

    includes="**/*.java
    

    Try simply pointing it to the root of your src dir (there is no need for the includes)

    <fileset dir="fw"  />
    

    But fw has to be the root of your sources, i.e. it contains the package folders like:

    src
     -org
       -module
         -MyClass1.java
         -MyClass2.java