The issue is that the applicationId on the testVariant is not available when configuring the Testify plugin. I verified that this is invoked in AfterEvaluate and should be valid at this point.
The documentation for testVariant says:
To process elements in this collection, you should use all. That's because the plugin populates this collection only after the project is evaluated. Unlike the each iterator, using all processes future elements as the plugin creates them.
I tried switching to using all and I still get an exception on the applicationId. Only a single testVariant is ever returned and it's always got an uninitialized applicationId.
According to this Stack Overflow post, this is an AGP bug and it is fixed in 7.1.0-alpha5. I verified that this does, indeed, work as expected. However, 7.1.0-alpha6 breaks again with the identical issue. So, I have reasoned that we can't wait on an upstream fix for this issue.
My solution here is to attempt to fetch the testVariant's applicationID, and if it fails, to fallback to the inferred applicationId prepended with .test. This should be correct for most instances, but may break some applications with customized product variants & flavors.
In the case where the test packaged ID is incorrectly inferred, the user can specify testify { testPackageId "my.custom.package.test" } in their build.gradle.
Tophat instructions
Check out this branch (it is upgraded to AGP 7)
Run ./gradlew tasks and verify that it completes successfully
Run all tests in the Sample app
Run ./gradlew Sample:testifySettings and verify that the testPackageId is correct set
What does this change accomplish?
Resolves #234
How have you achieved it?
The issue is that the
applicationId
on thetestVariant
is not available when configuring the Testify plugin. I verified that this is invoked inAfterEvaluate
and should be valid at this point.The documentation for
testVariant
says:I tried switching to using
all
and I still get an exception on theapplicationId
. Only a single testVariant is ever returned and it's always got an uninitializedapplicationId
.According to this Stack Overflow post, this is an AGP bug and it is fixed in 7.1.0-alpha5. I verified that this does, indeed, work as expected. However, 7.1.0-alpha6 breaks again with the identical issue. So, I have reasoned that we can't wait on an upstream fix for this issue.
My solution here is to attempt to fetch the testVariant's
applicationID
, and if it fails, to fallback to the inferredapplicationId
prepended with.test
. This should be correct for most instances, but may break some applications with customized product variants & flavors.In the case where the test packaged ID is incorrectly inferred, the user can specify
testify { testPackageId "my.custom.package.test" }
in theirbuild.gradle
.Tophat instructions
./gradlew tasks
and verify that it completes successfully./gradlew Sample:testifySettings
and verify that thetestPackageId
is correct set