PowerMockito and Jenkins coverage not measured

We have a setup where we use Jenkins, Clover, clover-ant and the jenkins-clover plugin to measure our codecoverage. We see that all unittest run with PowerMockito aren't taken into account in the clover report (codecoverage - 0%).

When when we run the unittest inside Eclipse with the eclipse-clover plugin the results are taken into account.

Any suggestion where to look for a solution?

11 answers

0 vote

It's worth to check whether the PowerMockito takes sources instrumented by Clover or the original ones. Please note that the Clover performs source code instrumentation so it should be called before PowerMockito, which works on the bytecode level.

Could share snippets of your build.xml with PowerMockito and Clover configuration and the order in which they're called?

Are you using <clover-setup> or <clover-instr>?

We are using clover-setup. But your remark concerning the order of calling is interesting, I will have to look into that...

It seems logical that this is the problem, I will look into it and come back here with the answer.

We are using clover-setup. But your remark concerning the order of calling is interesting, I will have to look into that...

It seems logical that this is the problem, I will look into it and come back here with the answer.

In the build logging I see that te code is intrumented before the tests are run:

Below is an anonymous output.

clover:
[clover-env] Loading clover.xml: jar:file:/&lt;pathto&gt;clover.xml
Trying to override old definition of task clover-env
[clover-setup] Clover Version 3.2.1, built on January 10 2014 (build-914)
[clover-setup] Loaded from: &lt;pathto&gt;\clover-ant-3.2.1\lib\clover.jar
[clover-setup] Clover: &lt;licence details&gt;
[clover-setup] Clover is enabled with initstring '&lt;pathto&gt;clover-db/coverage.db'
 
services.build:
    [mkdir] Created dir: &lt;pathto&gt;\services
    [javac] Compiling X source files to &lt;pathto&gt;
   [clover] Clover Version 3.2.1, built on January 10 2014 (build-914)
   [clover] Loaded from: &lt;pathto&gt;\lib\clover.jar
   [clover] Clover:  &lt;licence details&gt;
   [clover] Updating existing database at '&lt;pathto&gt;clover-db\coverage.db'.
   [clover] Processing files at 1.7 source level.
   [clover] Clover all over. Instrumented X files (14 packages).
   [clover] Elapsed time = 0.78 secs. (X files/sec, X srclines/sec)
      [jar] Building jar: &lt;pathto&gt;library.jar

tst.run:
    [junit] Running nl.sidn.&lt;pathtotestclass&gt;
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.11 sec

In the Clover coverage repport I can see that the code has no coverage, but that it's hit once in a test that is passed succesful... and that is confusing me... I've attached a detailed image.

0 vote
Are you running tests of an application running on a server? I'm asking because I suspect an issue with a flush policy - the global coverage recording file has not been written to a disk - try the <clover-setup flushpolicy="interval" flushinterval="1000"> ...
0 vote

More details about the coverage database and recording files:

and about the flush policy:

and how to deal with coverage of applications running on app servers:

I've done some additional testing with the flush policy. All three options (threaded, directed and interval) give the same results (coverage = 0%). Also completely removing the workspace to start clean didn't do anything.....

We are not testing against a server, so that shouldn't be an issue.

Belowe I've added the clover-setup we use in our ANT build script:

&lt;target name="with.clover"&gt;
  &lt;taskdef resource="cloverlib.xml" classpath="${clover.classpath}"/&gt;
  &lt;property name="test.target" value="tst.run" /&gt;
  &lt;property name="clover.dest" value="${build.dir}/clover" /&gt;
  &lt;clover-env/&gt;
  &lt;clover-setup initstring="${build.dir}/clover-db/coverage.db" tmpdir="${build.Clover}" flushpolicy="directed"&gt;
    &lt;files&gt;
      &lt;exclude name="**/generatedclassespackage1/**.java" /&gt;
      &lt;exclude name="**/generatedclassespackage2/**/*.java"/&gt;
    &lt;/files&gt;
  &lt;/clover-setup&gt;
&lt;/target&gt;

And the ant targets we run are "clean init with.clover build tst.run clover.report"

Hopefully this gives some new insight.... next up: make simple project to reproduce.... or investigate migrating to maven ;-)

0 vote
And how do you run PowerMockito?

this is our test target

<target name="tst.run" depends="services.tst.build, rest.tst.build">
<junit fork="false" forkmode="perTest" printsummary="yes" maxmemory="1024m" >
<jvmarg value="-Dfile.encoding=UTF-8"/>
<classpath>
<path refid="application.classpath" />
<path refid="eclipselink.libraryclasspath" />
<path refid="unittest.libraryclasspath"/>
<pathelement location="${build.services}"/>
<pathelement location="${build.web}"/>
<pathelement location="${clover.classpath}"/>
</classpath>
<formatter type="xml" />

<batchtest todir="${junit.xml.dir}" >
<fileset dir="${src.services.tst}">
<include name="**/*Test.java"/>
</fileset>
<fileset dir="${src.rest.tst}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
</target>

0 vote

May I ask you to create a ticket at https://support.atlassian.comin the "Clover Support" project and attach: build.xml, build log, small code sample? I'd like to investigate it furhter. We can later go back to this forum and post an answer as soon as I'll figure it out.

I will create an example project with all the problem, however due to other activities it might take a few week. thx for the replies.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Hipchat

Moving from Hipchat to Stride? Here’s what you’ll love

Heya, Hipchat friends! We’re so happy you’re checking out   Stride. Whether you know it or not, you have been instrumental in making Stride come to life. Every feature, design, and functionality...

59 views 2 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you