Unable to get Jacoco to work with Powermockito using offline instrumentation

前端 未结 12 1754
醉梦人生
醉梦人生 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:32

    I made it work using the javaagent of PowerMock. see here: https://github.com/powermock/powermock/wiki/PowerMockAgent

    Remove the @RunWith annotations, put the PowerMockRule as described in the link above. Make it public.

    Put the following line in the maven-surefire-plugin configuration:

    -javaagent:${org.powermock:powermock-module-javaagent:jar}
    

    (used the technique described here : Can I use the path to a Maven dependency as a property?)

    
    
        4.0.0
        com.stackoverflow
        q2359872
        2.0-SNAPSHOT
        q2359872
    
        
            
            ${org.jmockit:jmockit:jar}
        
        
            
                org.jmockit
                jmockit
                1.11
            
        
        
            generate-sources
            
                
                    org.apache.maven.plugins
                    maven-dependency-plugin
                    2.3
                    
                        
                            
                                properties
                            
                        
                    
                
                
                
                    org.codehaus.mojo
                    exec-maven-plugin
                    1.2
                    
                        
                            
                                exec
                            
                            generate-sources
                        
                    
                    
                        echo
                        
                            path to jar=
                            ${org.jmockit:jmockit:jar}
                            my.lib=
                            ${my.lib}
                        
                    
                
                
            
        
     
    

提交回复
热议问题