ndtp / android-testify

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

ISSUE-90: Add library sample #193

Closed djette-st closed 6 months ago

djette-st commented 7 months ago

What does this change accomplish?

Resolves #90

Configuring Testify for Android Library Projects

An Android library is structurally the same as an Android app module. It includes everything needed to build an app, including source code, resource files, and an Android manifest. So, it is often necessary to want to use screenshot testing with your library.

However, instead of compiling into an APK that runs on a device, an Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module. This means that Testify requires special configuration. The Testify Gradle Plugin is able to infer most configuration parameters for App modules, but for a Library module, some values must be specified in the build.gradle file.

In particular, unlike an App module, a Library project does not produce an APK of its own. Therefore, Testify must be configured to use the Library's generated instrumentation test runner APK as both the application under test and the test runner. These values are specified via the applicationPackageId and testPackageId Testify Extension values.

The applicationPackageId and testPackageId for a Library project will be the same value. You must specify this in your build.gradle file:

testify {
    applicationPackageId "dev.testify.samples.flix.library.test"
    testPackageId "dev.testify.samples.flix.library.test"
}

To find out what value to use for applicationPackageId and testPackageId, you can check the instrumentation name for your library by using the pm list instrumentation command on your emulator.

For example, to check the instrumentation name of the Flix Library sample project:

~>: ./gradlew FlixLibrary:installDebugAndroidTest
    Installing APK 'FlixLibrary-debug-androidTest.apk' on 'Testify(AVD) - 10' for :FlixLibrary:debug-androidTest
    BUILD SUCCESSFUL in 1s
    53 actionable tasks: 1 executed, 52 up-to-date

~>: adb shell pm list instrumentation
    instrumentation:dev.testify.samples.flix.library.test/androidx.test.runner.AndroidJUnitRunner (target=dev.testify.samples.flix.library.test)

Testify Configuration Values:


Sample

Please see the Flix Library sample for an example of using Testify with a library project.

More Information


Notice

[!WARNING] This change must keep main in a shippable state; it may be shipped without further notice.

AndroidTestifyBot commented 7 months ago

:white_check_mark: Success! - Legacy Sample screenshot test results

View build for commit b14f1b8d5fdf0cddd67671845c1338066c7dcc21
AndroidTestifyBot commented 7 months ago

:white_check_mark: Success! - Flix Sample screenshot test results

View build for commit b14f1b8d5fdf0cddd67671845c1338066c7dcc21
AndroidTestifyBot commented 7 months ago

:white_check_mark: Success! - Flix Library screenshot test results

View build for commit b14f1b8d5fdf0cddd67671845c1338066c7dcc21