Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

PowerMockito and Jenkins coverage not measured

Rik Ribbers January 22, 2014

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?

12 answers

0 votes
tbansal13861 September 25, 2018

 I am also facing same issue. We have configured clover in bamboo for ant project. Only for powermockito classes we are getting coverage as 0%. What was the solution for this issue?

0 votes
Rik Ribbers January 27, 2014

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.

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 27, 2014

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.

tbansal13861 September 24, 2018

@Marek Parfianowicz I am also facing same issue. We have configured clover in bamboo for ant project. Only for powermockito classes we are getting coverage as 0%. What was the solution for this issue?

0 votes
Rik Ribbers January 27, 2014

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 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 26, 2014
And how do you run PowerMockito?
0 votes
Rik Ribbers January 26, 2014

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 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2014

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:

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2014
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 votes
Rik Ribbers January 22, 2014

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 votes
Rik Ribbers January 22, 2014

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.

0 votes
Rik Ribbers January 22, 2014

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.

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2014

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>?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events