简体   繁体   English

摇篮| Jacoco任务| 测试报告

[英]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: 以下是我的查询:

  1. 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. 即使我不发表此声明,我仍然能够生成报告。

  2. What is testDebugUnitTest? 什么是testDebugUnitTest? How & where it's generated? 它是如何产生的?

  3. 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文件,那么有什么区别?

  4. Why different pattern for R class and Android classes? 为什么R类和Android类使用不同的模式?

    '* * /R.class' vs 'android/* * /* . '* * /R.class'与'android / * * / *。 * ' *'

  5. 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. 应报告覆盖率的来源集。

  1. What is executionData & testDebugUnitTest.exec ? 什么是executionDatatestDebugUnitTest.exec Is testDebugUnitTest.exec autogeenerated and why we need to mention this ? testDebugUnitTest.exec是否自动生成,为什么我们需要提到这一点?

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. 即使我不发表此声明,我仍然能够生成报告。

  • That means that your task call depended task before itself execute. 这意味着您的任务调用依赖于其自身执行之前的任务。

What is testDebugUnitTest? 什么是testDebugUnitTest? How & where it's generated? 它是如何产生的?

  • That is predefined job which starts all Tests. 这是预定义的作业,它将启动所有测试。

What is the difference between the pattern 模式之间有什么区别

' * * /R.class' and ' * * /R$*.class' '* * /R.class'和'* * /R$*.class'

  • ' * * /R.class' - files with R.class name in any path '* * /R.class'-在任何路径中具有R.class名称的文件
  • ' * * /R$*.class' - files with R prefix in name and .class extension in any path '* * /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 / * * / *。 * ' *'

  • 'android/* * /* . 'android / * * / *。 * ' also excluded some different files which complines that pattern *'还排除了一些不同的文件,这些文件使该模式更加复杂

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. 根据文档,两个来源集的描述是相同的,应该报告其覆盖率。

  • No difference. 没有不同。 additionalSourceDirs should be used for third party components if it make sense. 如果有意义,应该将AdditionalSourceDirs用于第三方组件。

What is executionData & testDebugUnitTest.exec? 什么是executionData&testDebugUnitTest.exec? Is testDebugUnitTest.exec autogeenerated and why we need to mention this ? testDebugUnitTest.exec是否自动生成,为什么我们需要提到这一点?

  • executionData - that is set of tests to run executionData-要运行的一组测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM