-
Notifications
You must be signed in to change notification settings - Fork 228
Gradle Setup
Setting up screenshot-tests-for-android in a gradle build is very straightforward. Assuming you're using the official android plugin, you just need to apply our plugin:
buildscript {
// ...
dependencies {
// ...
classpath 'com.facebook.testing.screenshot:plugin:0.2'
}
}
apply plugin: 'screenshot-tests-plugin'
By default this overrides your instrumentation test runner, and depending on your set up this can cause problems. See Custom InstrumentationTestRunners for how to avoid this.
This plugin sets up a few convenience commands:
gradle screenshotTests
will run all the instrumentation tests, and then generate a report of all of the screenshots.
gradle recordMode screenshotTests
will run all the screenshot tests and record all the screenshots in your screenshots/
. You can commit this directory into your repository.
gradle verifyMode screenshotTests
runs all the screenshot tests and compares it against the previously recorded screenshots. If any of them fails, this command will fail. We expect you to run this command in continuous integration.
The plugin also sets up compile dependencies for your tests, so you can now just start calling the Screenshot
API.See Creating a screenshot.
If your app supports multiple flavors, it's possible that your tests will not run properly using gradle screenshotTests
. Instead you will likely see an error along the lines of
Could not determine the dependencies of task ':your-app:pullScreenshots'. Task with path 'packageDebugAndroidTest' not found in project ':your-app'.
You need to add the following to your build.gradle:
screenshots {
testApkTarget = 'package<FlavorUnderTest>DebugAndroidTest'
connectedAndroidTestTarget = 'connected<FlavorUnderTest>DebugAndroidTest'
}
This will result in a successful test for a specific flavor.