-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate instrumentation tests #131
Integrate instrumentation tests #131
Conversation
…module and combines their execution data in a single report. Add the option to include instrumentation tests in the global merged report.
@@ -115,6 +115,10 @@ class GenerationPlugin implements Plugin<Project> { | |||
it.jacoco.includeNoLocationClasses = extension.includeNoLocationClasses | |||
} | |||
|
|||
if (extension.configureInstrumentationCoverage) { | |||
subProject.android.jacoco.version = extension.jacocoVersion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sets the Jacoco version for instrumentation tests
if (combined) { | ||
// add instrumentation coverage execution data | ||
executionData += subProject.fileTree("${subProject.buildDir}/outputs/code_coverage").matching { | ||
include "**/*.ec" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds the execution data from instrumentation tests to the report
* value is true. | ||
* @since 0.13.0 | ||
*/ | ||
boolean configureInstrumentationCoverage = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is enabled by default, but note that you need to manually set testCoverageEnabled true
nonetheless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get it to set the testCoverageEnabled
too?
* Note that this will run all instrumentation tests when true. | ||
* @since 0.13.0 | ||
*/ | ||
boolean includeInstrumentationCoverageInMergedReport = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this can be really heavy, I thought it's safer to turn this off by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup agreed. I also think the majority won't need a single report
private static void addJacocoTask(final boolean combined, final Project subProject, final JunitJacocoExtension extension, | ||
JacocoMerge mergeTask, JacocoReport mergedReportTask, final String taskName, | ||
final String jvmTestTaskName, final String instrumentationTestTaskName, final String sourceName, | ||
final String sourcePath, final String productFlavorName, final String buildTypeName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ugly to pass all these arguments, but I wanted to make the task creation reusable.
Codecov Report
@@ Coverage Diff @@
## master #131 +/- ##
============================================
+ Coverage 63.69% 66.85% +3.16%
- Complexity 34 36 +2
============================================
Files 1 1
Lines 157 175 +18
Branches 20 25 +5
============================================
+ Hits 100 117 +17
Misses 46 46
- Partials 11 12 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really liking it
README.md
Outdated
- Task `jacocoTestReport<Flavor><BuildType>` | ||
- Executes the `test<Flavor><BuildType>UnitTest` task before | ||
- Gets executed when the `check` task is executed | ||
- Generated Jacoco reports can be found under `build/reports/jacoco/<Flavor>/<BuildType>`. | ||
|
||
*Instrumentation tests* | ||
- Task `combinedTestReport<Flavor><BuildType>` | ||
- Executes the `test<Flavor><BuildType>UnitTest` and `create<Flavor><BuildType>CoverageReports` tasks before (JVM and instrumentation tests) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also capital Instrumentation
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation speaks of instrumented tests
(lowercase). I'll use that.
- Executes the `test<Flavor><BuildType>UnitTest` and `create<Flavor><BuildType>CoverageReports` tasks before (JVM and instrumentation tests) | ||
- Gets executed when the `check` task is executed | ||
- Generated Jacoco reports can be found under `build/reports/jacocoCombined/<Flavor>/<BuildType>`. | ||
Note that this task is only generated, if you set `testCoverageEnabled = true` for your [build type](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:testCoverageEnabled), e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense!
] | ||
def classPaths = [ | ||
"**/intermediates/classes/${sourcePath}/**", | ||
"**/intermediates/javac/${sourceName}/*/classes/**" // Android Gradle Plugin 3.2.x support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah here we already support AGP 3.2.x
import com.android.builder.model.BuildType | ||
import groovy.mock.interceptor.MockFor | ||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we keep this new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the provided editor config is messing with this.
Regarding |
Yes, that makes sense. I'll remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superb
Maybe I'm missing something but this breaks my pipeline currently. Before I had two test steps in my pipeline. I'd run |
@langerhans AFAIK @vanniktech I agree that this should be optional. What do you think? |
I guess so. |
Do you mean running unit tests AND instrumentation tests should be optional? I would agree. I can take a look, it shouldn't be hard. |
Yes. I'd assume then |
Yes, let me prepare something. |
Thanks for the quick replies! Also thanks for the hint about the duplicate tasks, I guess that was changed at some point. I have for now downgraded the plugin but I'll keep an eye on the releases here 👍 |
See #134 |
Generate a task that runs unit tests and instrumentation tests for a module and combines their execution data in a single report. Add the option to include instrumentation tests in the global merged report.