code coverage is 0% on offline instrumentation

543 views
Skip to first unread message

prave...@ebay.com

unread,
Feb 9, 2017, 12:19:12 PM2/9/17
to PowerMock
Hello,

When I use powermock in unit testing, coverage is 0% and I can find my classes in the session file generated with an ID but they are not linked. Both on the fly and offline instrumentation did not work. If i don't use powermock, i see code coverage. Really appreciate your help on this.

Version
Powermock : 1.7.0RC2
Easymock : 3.4
mockito : 2.4.0
jacoco : 0.7.7.201606060606

Removed javassist dependency from my pom

References


POM
<plugin>
 
<groupId>org.jacoco</groupId>
 
<artifactId>jacoco-maven-plugin</artifactId>
 
<executions>
 
<execution>
                       
<id>default-instrument</id>
                       
<goals>
                           
<goal>instrument</goal>
                       
</goals>
                       
<configuration><includes><include>**/*test*</include></includes></configuration>
                   
</execution>
                   
<execution>
                       
<id>default-restore-instrumented-classes</id>
                       
<goals>
                           
<goal>restore-instrumented-classes</goal>
                       
</goals>
                         
<configuration><includes><include>**/*test*</include></includes></configuration>
                   
</execution>
                   
<execution>
                       
<id>report</id>
                       
<phase>prepare-package</phase>
                       
<goals>
                           
<goal>report</goal>
                       
</goals>
                       
<configuration>
                           
<dataFile>${project.basedir}/../target/jacoco.exec</dataFile>
                       
</configuration>
                   
</execution>
                   
<execution>
           
<id>report-aggregate</id>
           
<phase>verify</phase>
           
<goals>
             
<goal>report-aggregate</goal>
           
</goals>
         
</execution>
           
<execution>
           
<id>Prepare-Jacoco</id>
           
<goals>
               
<goal>prepare-agent</goal>
           
</goals>
           
<configuration><excludes><exclude>**/*test*</exclude></excludes></configuration>
       
</execution>
 
</executions>
 
<configuration>
 
<dataFile>${project.basedir}/../target/jacoco.exec</dataFile>
 
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
 
<append>true</append>
 
<propertyName>surefireargs</propertyName>
<!--
For the the fly
<execution>

 <id>pre-unit-test</id>
 <goals>
 <goal>prepare-agent</goal>
 </goals>
 </execution>
 <execution>
 <id>post-unit-test</id>
 <phase>prepare-package</phase>
 <goals>
 <goal>report</goal>
 </goals>
 </execution>-->
 
 
</configuration>
 
</plugin>


Thank you,
Praveen

Zagretdinov Arthur

unread,
Feb 9, 2017, 1:15:00 PM2/9/17
to powe...@googlegroups.com
Hello, 

Could you provided code example? I can guess what code doesn’t have coverage in report, because code mocked and is not called. 

Best regrads,
Arthur Zagretdinov
--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at https://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.

prave...@ebay.com

unread,
Feb 9, 2017, 2:09:40 PM2/9/17
to PowerMock
Thank you Arthur for looking in to this issue. I have coverage working for my project in the below configuration. So I don't think there is any issue with the code.

Powermock : 1.6.2
Easymock: 3.3.1
Mockito: 1.10.19
Jacoco: 0.7.2.201409121644

Latest version of Jacoco Plugin (2.1.0) on Jenkins does not support old version of reports, which is the primary motivation for me to update the plugins.

However, here is a code sample. 
@RunWith(PowerMockRunner.class)
@PrepareForTest({Classtobemocked1.class, Classtobemocked2.class})
public class ClassTests {
@Test
public void test1() {
Classtobemocked1 mock = PowerMockito.mock(Classtobemocked1.class);
PowerMockito.when(mock.getCount()).thenReturn(10);
}
}

Sorry I am not allowed to share the actual code.

Once I upgraded the versions as stated in the first post, i started getting few errors due to Mockito API
1. Mockito.spy() works only on mock objects (Fix: Spy on an instance)
2. Class xxx is not prepared for test. (Fix: add appropriate classes to @PrepareForTest)


Thanks,
Praveen


On Thursday, February 9, 2017 at 10:15:00 AM UTC-8, Артур Загретдинов wrote:
Hello, 

Could you provided code example? I can guess what code doesn’t have coverage in report, because code mocked and is not called. 

Best regrads,
Arthur Zagretdinov

Pankaj Trivedi

unread,
Feb 5, 2018, 3:02:30 PM2/5/18
to PowerMock
Hi, 

Were you able to solve this? Was there any solution to this?
Reply all
Reply to author
Forward
0 new messages