I know this is a known issue while working with Jacoco and PowerMock(or any Mocking framework that modifies the class) together. I have googled online a lot and I did find a nice working example for Jmockit and Jacoco to work together for Maven build project which was posted by Evengy Gudkov but I could not find any example where Jacoco and PowerMock working together in ANT base project. If anyone has ever worked on this or if anyone could post a working example on Jacoco and PowerMock for ant build project it would be really great. I have tried but no luck.
Approach 1:
<junit printsummary="true" failureproperty="junit.failure" fork="true">
<classpath path="${unittest-mockitoJar}" /> ----> I have made sure that PowerMock jar is before Junit jar
<bootclasspath>
<pathelement path="${libdir}/jacoco/jacocoagent.jar}"/>
<pathelement path="C:/gec/10.0.0/gc/instrumented-Classes" /> ----> instrumented classes
</bootclasspath>
<classpath path="${gec-thirdparty-jars}"></classpath>
<sysproperty key="jacoco-agent.destfile" file="${target.exec.file}"/>
<batchtest todir="${test-xml-reports}">
<fileset dir="${classes}" excludes="com/geic/test/util/**,com/geic/test/testlib/**"/> ----> where ${classes} are unit test classes
<formatter type="xml"/>
</batchtest>
</junit>
Approach 2:
<jacoco:coverage destfile="${gecdir}/lib/jacoco/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant"> -->
<junit printsummary="true" failureproperty="junit.failure" fork="true">
<classpath path="${unittest-mockitoJar}" />
<classpath path="${libdir}/jacoco/jacocoagent.jar}" />
<classpath path ="C:/gec/10.0.0/gc/instrumented-Classes" /> -->
<classpath path="${gec-thirdparty-jars}"></classpath>
<sysproperty key="jacoco-agent.destfile" file="${target.exec.file}"/>
<batchtest todir="${test-xml-reports}">
<fileset dir="${classes}" excludes="com/gec/test/util/**,com/gec/test/testlib/**"/>
<formatter type="xml"/>
</batchtest>
</junit>
</jacoco:coverage>