通过在真实应用程序上运行验收测试获取 jacoco 报告 [英] Get jacoco report from running acceptance test on real application
问题描述
我是 sonar 和 jacoco 的新手,我无法找到以下问题的答案
我们将使用 sonar 和 jacoco 来分析我们的测试覆盖率.
我们将进行三种测试:单元测试、集成测试(使用 Spring Boot 测试)和验收测试,我们将在真实的应用程序实例上运行.我们想合并测试结果.为单元和集成测试生成 jacoco 文件不是问题,因为它们可以访问源代码.我们可以在声纳中合并这些报告.
我的问题是可以生成 jacoco 文件用于与实际应用程序交互的验收测试吗?也许你会有一个如何做的链接?
我目前最好的想法是在实际应用程序和嵌入式应用程序上运行两次验收测试,并从嵌入式获取报告.但也许有更好的解决方案.谢谢,
JaCoCo 能够记录任何类型的 Java 应用程序的执行 - 你只需要用
报告源文件:
jacoco-0.8.0/lib/jacococli.jar 报告 jacoco.exec--classfiles 类--html 报告--sourcefiles 源文件
现在关于 SonarQube:它执行 exec
和类文件的分析,因此要求类文件与运行时使用的相同以生成 exec
文件.因此,您需要保证对与测试中完全相同的类文件执行 SonarQube 分析.
I'm new to sonar and jacoco and I wasn't able to find an ansewer to following question
We are going to use sonar and jacoco to analyze our test coverage.
We are going to have three kind of test: unit test, integration test (use spring boot test) and acceptance test that we will run on real application instance. We want to merge test results. To generating jacoco files for unit and integration tests is not a problem as they have access to source code. And we can merge this reports in sonar.
My question is it possible to generate jacoco file for acceptance test which interacts with real application? And maybe you will have a link to how to do it?
My best idea for now is to run acceptance tests twice on both real application and embedded one, and get report from embedded. But maybe there is better solution. Thanks,
JaCoCo is able to record any kind of execution of Java application - you just need to start this application with agent, for example:
java -javaagent:jacoco-0.8.0/lib/jacocoagent.jar -cp classes Main
By default at termination of application this will produce file jacoco.exec
with execution data. There are also ways to get execution data from running application.
And there are plenty of examples all over the internet of using agent in various cases - with Spring Boot, Tomcat, Weblogic, etc.
After that report can be generated using this execution data jacoco.exec
and exactly the same class files that were used at runtime for generation of execution data. For example using JaCoCo command line interface (there are also Ant tasks, Gradle plugin, Maven plugin):
java -jar jacoco-0.8.0/lib/jacococli.jar
report
jacoco.exec
--classfiles classes
--html report
Report can be generated without source files, but in this case you won't be able to drill down lower than method level granularity:
Report with source files:
jacoco-0.8.0/lib/jacococli.jar
report
jacoco.exec
--classfiles classes
--html report
--sourcefiles src
Now about SonarQube: it performs analysis of exec
and class files, and so also requires that class files are the same as where used at runtime for generation of exec
file. So you need to guarantee that SonarQube analysis is performed for exactly the same class files as under testing.
这篇关于通过在真实应用程序上运行验收测试获取 jacoco 报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!