Skip to content
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

Merged
merged 4 commits into from
Oct 11, 2018
Merged

Integrate instrumentation tests #131

merged 4 commits into from
Oct 11, 2018

Conversation

vRallev
Copy link
Collaborator

@vRallev vRallev commented Oct 11, 2018

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.

…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
Copy link
Collaborator Author

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"
}
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

Copy link
Owner

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
Copy link
Collaborator Author

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

Copy link
Owner

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) {
Copy link
Collaborator Author

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
Copy link

codecov bot commented Oct 11, 2018

Codecov Report

Merging #131 into master will increase coverage by 3.16%.
The diff coverage is 84.48%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...ktech/android/junit/jacoco/GenerationPlugin.groovy 66.85% <84.48%> (+3.16%) 36 <2> (+2) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 331fa7b...7e5fa38. Read the comment docs.

Copy link
Owner

@vanniktech vanniktech left a 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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also capital Instrumentation?

Copy link
Collaborator Author

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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes sense!

README.md Outdated Show resolved Hide resolved
]
def classPaths = [
"**/intermediates/classes/${sourcePath}/**",
"**/intermediates/javac/${sourceName}/*/classes/**" // Android Gradle Plugin 3.2.x support.
Copy link
Owner

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

Copy link
Owner

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?

Copy link
Collaborator Author

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.

@vanniktech
Copy link
Owner

Regarding configureInstrumentationCoverage and testCoverageEnabled, can we get rid of configureInstrumentationCoverage and just use the testCoverageEnabled. That way consumers can define where they want things to be added or not and they're not forced to be using 2 options.

@vRallev
Copy link
Collaborator Author

vRallev commented Oct 11, 2018

Yes, that makes sense. I'll remove configureInstrumentationCoverage

Copy link
Owner

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superb

@vRallev vRallev merged commit 1950af8 into vanniktech:master Oct 11, 2018
@vRallev vRallev deleted the task/instrumentation-coverage branch October 11, 2018 16:20
@langerhans
Copy link

Maybe I'm missing something but this breaks my pipeline currently. Before I had two test steps in my pipeline. I'd run ./gradlew :app:connectedDebugAndroidTest :app:createDebugCoverageReport [... more modules] and in the following step ./gradlew mergeJacocoReports. The first part would execute only the Android instrumentation tests, second one would execute only the unit tests and then merge the reports of both runs.
But now mergeJacocoReports will also execute instrumentation tests. It's not clear to me how to reproduce the old behavior after this PR.
Reason to do it that way is that we have a pretty large instrumentation test set and use lockable resources to not block our jenkins slots too much.

@vRallev
Copy link
Collaborator Author

vRallev commented Oct 16, 2018

@langerhans AFAIK createDebugCoverageReport runs instrumentation tests, too. But I see, that now mergeJacocoReports runs the instrumentation tests as well.

@vanniktech I agree that this should be optional. What do you think?

@vanniktech
Copy link
Owner

createDebugCoverageReport runs the tests - yeah. AFAIK.

@vanniktech I agree that this should be optional. What do you think?

I guess so. mergeJacocoReports should only take the outputs then and running them should not be a dependency. (Should be consistent between Android + Java projects)

@vRallev
Copy link
Collaborator Author

vRallev commented Oct 16, 2018

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.

@vanniktech
Copy link
Owner

Yes. I'd assume then mergeJacocoReports only merges them (as the name states) and you need to take care the reports are present (running instrumentation tests / running tests manually).

@vRallev
Copy link
Collaborator Author

vRallev commented Oct 16, 2018

Yes, let me prepare something.

@langerhans
Copy link

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 👍

@vRallev
Copy link
Collaborator Author

vRallev commented Oct 18, 2018

See #134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants