[英]Gradle | Jacoco Task | test report
In some blog, I found below task to generate the jacoco report: 在一些博客中,我找到了以下任务来生成jacoco报告:
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") {
group = "Verification"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}
classDirectories = fileTree(
dir: "${project.buildDir}/intermediates/classes/debug",
excludes: ['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'android/**/*.*'
])
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files('build/jacoco/testDebugUnitTest.exec')
}
I am new to Gradle and I want to understand each step of this task in detail. 我是Gradle的新手,我想详细了解此任务的每个步骤。 Below are my queries:
以下是我的查询:
What is the functionality of dependsOn: "testDebugUnitTest" while creating a new task? 创建新任务时, dependsOn:“ testDebugUnitTest”的功能是什么? Even if I don't put this statement, still I am able to generate the report.
即使我不发表此声明,我仍然能够生成报告。
What is testDebugUnitTest? 什么是testDebugUnitTest? How & where it's generated?
它是如何产生的?
What is the difference between the pattern 模式之间有什么区别
' * * /R.class' and ' * * /R$*.class' '* * /R.class'和'* * /R$*.class'
Both are excluding the R files from report then what is the difference? 两者都从报告中排除了R文件,那么有什么区别?
Why different pattern for R class and Android classes? 为什么R类和Android类使用不同的模式?
'* * /R.class' vs 'android/* * /* . '* * /R.class'与'android / * * / *。 * '
*'
What is the difference between additionalSourceDirs & source directories? AdditionalSourceDirs和源目录之间有什么区别? As per the documentation, description is same for both
根据文档,两者的描述相同
Source sets that coverage should be reported for.
应报告覆盖率的来源集。
What is the functionality of dependsOn: "testDebugUnitTest" while creating a new task?
创建新任务时,dependsOn:“ testDebugUnitTest”的功能是什么? Even if I don't put this statement, still I am able to generate the report.
即使我不发表此声明,我仍然能够生成报告。
This ensures that testDebugUnitTest runs before jacocoTestReport. 这样可以确保testDebugUnitTest在jacocoTestReport之前运行。 You usually set up such task dependencies because one task depends on the output of another.
您通常会设置此类任务依赖项,因为一个任务取决于另一个任务的输出。 In this case, you want the tests to run — via testDebugUnitTest — before you try to generate a report for them.
在这种情况下,您希望通过testDebugUnitTest运行测试,然后再尝试为它们生成报告。
BTW, I believe Jacoco works by instrumenting the class files generated by the compiler. 顺便说一句,我相信Jacoco可以通过检测编译器生成的类文件来工作。 This instrumentation generates data that Jacoco can then analyse to determine whether methods are called or not.
该仪器生成Jacoco可以分析的数据,以确定是否调用方法。 But you need to execute the code in order to get that data, hence why you run the tests first.
但是您需要执行代码才能获取该数据,因此为什么要先运行测试。
What is testDebugUnitTest?
什么是testDebugUnitTest? How & where it's generated?
它是如何产生的?
This is a task. 这是一个任务。 Tasks can be defined in your build script, a parent build script or added via plugins.
可以在构建脚本,父构建脚本中定义任务,也可以通过插件添加任务。 The example code you show doesn't tell us anything about where this task is coming from.
您显示的示例代码不会告诉我们该任务的来源。
Having said that, it seems that the Android plugin sets this task up. 话虽如此,Android插件似乎可以完成此任务。
What is the difference between the pattern
模式之间有什么区别
' * * /R.class' and ' * * /R$*.class'
'* * /R.class'和'* * /R$*.class'
Compiled inner and anonymous class files are named as '$.class'. 编译后的内部和匿名类文件名为“ $ .class”。 This is just ensuring that Jacoco picks up those inner and anonymous classes.
这只是确保Jacoco选择了那些内部和匿名类。
Why different pattern for R class and Android classes?
为什么R类和Android类使用不同的模式?
'* * /R.class' vs 'android/* * /* .
'* * /R.class'与'android / * * / *。 * '
*'
No idea. 不知道。 I don't know what this
R
class is. 我不知道这是
R
类。 The Android pattern is simply narrower, since it's working on the basis that Android classes are somewhere in an android folder. Android模式只是缩小了范围,因为它是基于Android类位于android文件夹中的某个位置而工作的。
What is the difference between additionalSourceDirs & source directories?
AdditionalSourceDirs和源目录之间有什么区别? As per the documentation, description is same for both
根据文档,两者的描述相同
I don't know for sure, but it seems that sourceDirectories
is for source sets . 我不确定,但似乎
sourceDirectories
是用于源集的 。 Note that the task has a sourceSets()
method. 请注意,该任务具有
sourceSets()
方法。 This populates the sourceDirectories
file collection. 这将填充
sourceDirectories
文件集合。
additionalSourceDirectories
appears to be for other source directories that aren't defined as part of a source set. additionalSourceDirectories
似乎用于未定义为源集一部分的其他源目录。
Honestly, this task seems to be pretty badly documented. 老实说,这个任务似乎没有很好的记录。
What is executionData & testDebugUnitTest.exec?
什么是executionData&testDebugUnitTest.exec? Is testDebugUnitTest.exec autogeenerated and why we need to mention this ?
testDebugUnitTest.exec是否自动生成,为什么我们需要提到这一点?
I'm guessing that testDebugUnitTest.exec
is a file that is generated when you run the instrumented classes via the debug unit tests. 我猜想
testDebugUnitTest.exec
是当您通过调试单元测试运行检测类时生成的文件。 executionData
is a way to tell the JacocoReport
task where to find that file. executionData
是一种告诉JacocoReport
任务在哪里找到该文件的方法。 But as I said, I'm taking an educated guess. 但是正如我所说,我正在接受有根据的猜测。
What is the functionality of dependsOn: "testDebugUnitTest" while creating a new task?
创建新任务时,dependsOn:“ testDebugUnitTest”的功能是什么? Even if I don't put this statement, still I am able to generate the report.
即使我不发表此声明,我仍然能够生成报告。
What is testDebugUnitTest?
什么是testDebugUnitTest? How & where it's generated?
它是如何产生的?
What is the difference between the pattern
模式之间有什么区别
' * * /R.class' and ' * * /R$*.class'
'* * /R.class'和'* * /R$*.class'
Both are excluding the R files from report then what is the difference?
两者都从报告中排除了R文件,那么有什么区别? Why different pattern for R class and Android classes?
为什么R类和Android类使用不同的模式?
'* * /R.class' vs 'android/* * /* .
'* * /R.class'与'android / * * / *。 * '
*'
What is the difference between additionalSourceDirs & source directories?
AdditionalSourceDirs和源目录之间有什么区别? As per the documentation, description is same for both Source sets that coverage should be reported for.
根据文档,两个来源集的描述是相同的,应该报告其覆盖率。
What is executionData & testDebugUnitTest.exec?
什么是executionData&testDebugUnitTest.exec? Is testDebugUnitTest.exec autogeenerated and why we need to mention this ?
testDebugUnitTest.exec是否自动生成,为什么我们需要提到这一点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.