Merging Integration and Unit test reports with JaCoCo

后端 未结 5 1467
無奈伤痛
無奈伤痛 2020-12-23 16:53

I am generating failsafe and surefire reports with maven with the JaCoCo plugin, but I can only manage to get them in separate reports. I would like to have a overall covera

5条回答
  •  有刺的猬
    2020-12-23 17:43

    I recently implemented this: after some headaches and a lot of testing, I have a configuration that works beautifully.

    
        org.jacoco
        jacoco-maven-plugin
        ${jacoco.version}
        
            
                pre-unit-test
                
                    prepare-agent
                
                
                    ${project.build.directory}/coverage-reports/jacoco-ut.exec
                    surefireArgLine
                
            
            
                pre-integration-test
                
                    prepare-agent-integration
                
                
                    ${project.build.directory}/coverage-reports/jacoco-it.exec
                    testArgLine
                
            
            
                post-integration-test
                post-integration-test
                
                    report
                
                
                    ${project.build.directory}/coverage-reports/jacoco-it.exec
                    ${project.reporting.outputDirectory}/jacoco-it
                
            
            
                post-unit-test
                prepare-package
                
                    report
                
                
                    ${project.build.directory}/coverage-reports/jacoco-ut.exec
                    ${project.reporting.outputDirectory}/jacoco-ut
                
            
            
                merge-results
                verify
                
                    merge
                
                
                    
                        
                            ${project.build.directory}/coverage-reports
                            
                                *.exec
                            
                        
                    
                    ${project.build.directory}/coverage-reports/aggregate.exec
                
            
            
                post-merge-report
                verify
                
                    report
                
                
                    ${project.build.directory}/coverage-reports/aggregate.exec
                    ${project.reporting.outputDirectory}/jacoco-aggregate
                
            
        
    
    
        org.apache.maven.plugins
        maven-surefire-plugin
        2.18.1
        
            ${surefireArgLine}
            ${skip.unit.tests}
            
                **/*UT.java
                **/*MT.java
                **/*Test.java
            
            ${skipUTMTs}
        
    
    
        org.apache.maven.plugins
        maven-failsafe-plugin
        2.12.4
        
            ${skipTests}
            ${skipITs}
            ${testArgLine}
            
                **/*UT*.java
            
        
        
            
                
                    integration-test
                    verify
                
            
        
    
    

    As you can see, there are 6 distinct Jacoco executions to run the tests, merge the files and create an aggregate report. On top of the Jacoco config, you also need to configure Surefire and Failsafe to take an argument from Jacoco (Surefire runs the unit tests and Failsafe runs the integration tests).

    All of the configuration that I used should be there, what you do with it is your design architecture to make it fit within your desired requirements. Personally, I recommend a look into what I exclude and include within surefire and failsafe if you are having issues with files not being read.

提交回复
热议问题