通过在实际应用程序上运行验收测试获取jacoco报告 [英] Get jacoco report from running acceptance test on real application

查看:94
本文介绍了通过在实际应用程序上运行验收测试获取jacoco报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是声纳和雅各布的新手,无法找到解决以下问题的答案

I'm new to sonar and jacoco and I wasn't able to find an ansewer to following question

我们将使用声纳和jacoco分析我们的测试覆盖率.

We are going to use sonar and jacoco to analyze our test coverage.

我们将要进行三种测试:单元测试,集成测试(使用spring boot测试)和验收测试,我们将在真实的应用程序实例上运行它们.我们要合并测试结果.生成用于单元测试和集成测试的jacoco文件不是问题,因为它们可以访问源代码.我们可以将这些报告合并在声纳中.

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.

我的问题是可以生成与实际应用程序交互的用于接受测试的jacoco文件吗?也许您将获得如何执行操作的链接?

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能够记录任何类型的Java应用程序执行-您只需要使用

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

默认情况下,在应用程序终止时,这将生成带有执行数据的文件jacoco.exec.还有从运行的应用程序获取执行数据的方式.

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.

互联网上有很多在各种情况下使用代理的示例- Tomcat Weblogic 等.

And there are plenty of examples all over the internet of using agent in various cases - with Spring Boot, Tomcat, Weblogic, etc.

之后,可以使用此执行数据jacoco.exec 与运行时用于生成执行数据的类文件完全相同 .例如,使用 JaCoCo命令行界面(也有蚂蚁任务 Maven插件):

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:

带有源文件的报告:

jacoco-0.8.0/lib/jacococli.jar \
  report \
  jacoco.exec \
  --classfiles classes \
  --html report \
  --sourcefiles src

现在有关SonarQube的信息:它执行exec和类文件的分析,因此还要求类文件与运行时用于生成exec文件的文件相同.因此,您需要保证SonarQube分析是针对与测试中完全相同的类文件执行的.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆