问题描述
有没有人尝试过配置 jacoco 以将单元和集成测试的覆盖率转储到 2 个不同的文件中,以便 sonar 使用它们,使用 ant 构建?
has any one tried configuring jacoco to dump the coverage of unit and integration tests in 2 different files, for sonar to use them, using ant build?
推荐答案
这是一个可行的尊龙凯时的解决方案,为单元测试和集成测试生成报告.此尊龙凯时的解决方案使用 append 策略.
here is a working solution, generating the report for both unit tests and integration tests. this solution is using the append strategy.
请注意,为了在 apply 策略上正常工作,阶段应按顺序执行(如果 mvn test 和 mvn verify -dskipunittests 将并行执行,可能无法正常工作).
please note that in order to work properly on the apply strategy, the phases should be executed sequentially (if the mvn test and mvn verify -dskipunittests will be executed in parallel there is possible to not work fine).
org.jacoco jacoco-maven-plugin ${jacoco.version} ${skiptests} true ${project.build.directory}/coverage-reports/jacoco_aggregation.exec ${project.build.directory}/coverage-reports/jacoco_aggregation.exec ${project.reporting.outputdirectory}/jacoco pre-unit-test prepare-agent surefireargline post-unit-test test report pre-integration-test pre-integration-test prepare-agent failsafeargline post-integration-test post-integration-test report org.apache.maven.plugins maven-surefire-plugin ${surefireargline} org.apache.maven.plugins maven-failsafe-plugin ${failsafeargline}
生成报告后,您可以执行声纳命令来应用报告.
once the reports are generated, you can execute the sonar commant to apply the reports.
mvn sonar:sonar -dsonar.coverage.jacoco.xmlreportpaths="target/site/jacoco/jacoco.xml"