Unable to get Jacoco to work with Powermockito using offline instrumentation

前端 未结 12 1739
醉梦人生
醉梦人生 2020-12-13 01:56

Given that Jacoco doesn\'t play nicely with PowerMockito when instrumenting \"on the fly\", I\'ve been trying to configure offline instrumentation in the hope this will give

12条回答
  •  执念已碎
    2020-12-13 02:52

    I was also facing the same issue. I was able to generate report partially. I have used both these tags for my test cases @RunWith(PowerMockRunner.class) @PrepareForTest({}). And the report was not getting generated for the test cases where i used the above mentioned tags. But for one of the test case there was only this tag @RunWith(PowerMockRunner.class). Somehow the report was getting generated for that case. And also i have never used offline instrumentation. When i tried using the offline instrumentation i was getting error saying that the class was already instrumented. I tried various scenarios and followed various links but could not generate the report. Finally as per the above comment i upgraded my version of powermock from 1.5.5 to 1.6.5 and i was able to generate the report. Following is my pom.xml entry

         
        org.jacoco
        jacoco-maven-plugin
        0.7.5.201505241946
        
            
                pre-unit-test
                
                    prepare-agent
                
                 
                        
                        ${basedir}/target/jacoco.exec
                        
                
            
            
                
                default-report
                verify
                
                    report
                
                  
                    
                    ${basedir}/target/jacoco.exec
                    
                    ${basedir}/target/jacoco-ut
                
            
        
    
    

    Following is my entry in pom .xml for maven-surefire-plugin

        
            org.apache.maven.plugins
            maven-surefire-plugin
          
                @{argLine}
                false
                true
            
        
    

    @{argLine} was set as a property

    
        -noverify -Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m
    
    

    And upgraded my powermock version from 1.5.5 to 1.6.5 . Finally i could see my report generation for the classes where i used the following tags in my test cases @RunWith(PowerMockRunner.class) @PrepareForTest({})

提交回复
热议问题