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

How to use testify with custom build type? #131

Open
bkonrad-check opened this issue May 8, 2023 · 4 comments
Open

How to use testify with custom build type? #131

bkonrad-check opened this issue May 8, 2023 · 4 comments
Labels
Bug Any behaviour the deviates from the documentation, expected outcome or API contract. Documentation

Comments

@bkonrad-check
Copy link

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

bkonrad-check commented May 8, 2023

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 DanielJette added Documentation Bug Any behaviour the deviates from the documentation, expected outcome or API contract. Testify 2.0 labels May 8, 2023
@DanielJette
Copy link
Contributor

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

zhkvdm commented Sep 10, 2023

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

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any behaviour the deviates from the documentation, expected outcome or API contract. Documentation
Projects
None yet
Development

No branches or pull requests

3 participants