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

Added androidTest coverage support #16

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gmazzo
Copy link
Owner

@gmazzo gmazzo commented May 5, 2023

Draft WIP implementing #15: support for AndrodiTest variant.

The aggregation functionally was extended to also allow including AndroidTest variants.

The current implementation is hacky, accessing AGP's internal APIs by reflection. More details here .

@@ -1,6 +1,6 @@
[versions]
kotlin = "1.8.21"
agp = "8.0.0"
agp = "8.2.0-alpha02"
Copy link
Owner Author

Choose a reason for hiding this comment

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

There is an issue with 8.0.1 producing empty results for library modules

import kotlin.reflect.jvm.isAccessible
import kotlin.reflect.typeOf

internal fun <FILE_TYPE : FileSystemLocation> Artifacts.get(
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is a blocker to me, I don't want to release code doing all this dark magic to access the artifacts

}
}

if (variant.unitTest != null && buildType.enableUnitTestCoverage) {
aggregate(variant.unitTest!!.artifacts.get(UNIT_TEST_CODE_COVERAGE))
Copy link
Owner Author

Choose a reason for hiding this comment

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

This internal artifact points to the "build/jacoco/testXXXUnitTest.exec" files

Comment on lines 117 to 89
files(this).asFileTree.forEach { file ->
outgoing.artifact(file) {
type = ArtifactTypeDefinition.BINARY_DATA_TYPE
builtBy(this@file)
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

And this is not working well, as for AndroidTest we know in advance the target output directory, but not all the .ec files getting generated by each emulator.

into(provider { temporaryDir })
duplicatesStrategy = DuplicatesStrategy.INCLUDE // in case of duplicated classes
include("**/*.class")
Copy link
Owner Author

Choose a reason for hiding this comment

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

Now required, as the PRE_JACOCO_TRANSFORMED_CLASSES also includes R.jar from its dependencies

aggregatedVariants.all task@{
from(artifacts
.forScope(ScopedArtifacts.Scope.PROJECT)
.get(PRE_JACOCO_TRANSFORMED_CLASSES))
Copy link
Owner Author

Choose a reason for hiding this comment

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

I've been forced to change from ScopedArtifact.CLASSES (public API) to InternalScopedArtifact .PRE_JACOCO_TRANSFORMED_CLASSES because ScopedArtifact.CLASSES gets replaced with JaCoCo instrumented classes when AndroidTest coverage is enabled. JaCoCo report task won't accept instrumented classes

@gmazzo gmazzo force-pushed the android-test-coverage-support branch from f690d06 to 6945d09 Compare November 12, 2023 22:57
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.

None yet

1 participant