ndtp / android-testify

Add screenshots to your Android tests
Other
98 stars 5 forks source link

How to use testify with custom build type? #131

Open bkonrad-check opened 1 year ago

bkonrad-check commented 1 year ago

Hey there,

in our app we have an custom build type for us, on which our instrumentation tests rely,, which is called GoogleMock, so build type and flavor. So the default installDebug isn't working. I set this up like this:

extensions.configure<TestifyExtension>{
            this.installTask = "installGoogleMock"
            this.installAndroidTestTask = "installGoogleMockAndroidTest"
        }

This isn't working, since for some reason the androidx.test.runner.AndroidJUnitRunner cannot be found. The error looks like:

  No failed screenshots found
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{packageName.test/androidx.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS_CODE: -1
  Pulling screenshots:
  No failed screenshots found

However, if I use an example project, where I don't have the build type, same dependency versions and just use debug everything is working fine. So I guess either I have to configure something else or there might be an issue in testify, which leads to not working code in case of build variants. Look forward for help, thanks!

bkonrad-check commented 1 year ago

Okay, it seems like i was missing some additions, that were not mentioned in the docs. If I use it like the following it is working:

extensions.configure<TestifyExtension>{
            this.installTask = "installGoogleMock"
            this.installAndroidTestTask = "installGoogleMockAndroidTest"
            this.testPackageId = "com.example.snapshotplayground.mock.test"
            this.applicationPackageId = "com.example.snapshotplayground.mock"
        }

Maybe you could improve the docs here, since this was really tricky to find out.

DanielJette commented 1 year ago

@bkonrad-check Thank you for logging this issue.

Support for multi-modules and custom build types is an emerging topic of interest. Testify can be customized for many build configurations, but most of the that support was added to the codebase long ago, but without the necessary documentation. It's a priority for us to include more detailed and advanced guidance on handling these scenarios.

We're also working on updating the Sample to include more realistic, real-world examples which will be useful for helping developers set up Testify in their apps.

zhkvdm commented 9 months ago

Hey! I've faced the same issue in app module. Module configuration is

extensions.configure<dev.testify.TestifyExtension> {
    applicationPackageId = "ru.myapp.feature.codeinput"
    testPackageId = "ru.myapp.feature.codeinput.test"
}

android {
    resourcePrefix = "codeinput_"
    namespace = "ru.myapp.feature.codeinput"
}

But I gets error then running ./gradlew :feature:code-input-impl:screenshotRecord. Error is the same as @bkonrad-check gets:

INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{ru.myapp.feature.codeinput.test/androidx.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1

UPD: Fix that by run task ./gradlew installDebugAndroidTest before ./gradlew screenshotRecord. Because instrumentation packages haven't been installed on device when I run just screenshotRecord. Should I always run installDebugAndroidTest firstly?

DanielJette commented 9 months ago

@zhkvdm installDebugAndroidTest should automatically be run by screenshotRecord as it is normally set as a task dependency.

If this isn't working, it's possible the auto-detection of the tasks is failing for your project. You can try to manually configure the task dependency in your build.gradle file.

You can try setting:

testify {
    installAndroidTestTask ":my_module:installDebugAndroidTest"
}

You can also try running in "verbose" mode as this will print out the underlying adb commands for you to inspect and see what Testify is trying to do. To enable verbose mode, add -Pverbose=true to your gradle command:

./gradlew screenshotTest -Pverbose=true