Skip to content

Instantly share code, notes, and snippets.

@malvinstn
Last active October 24, 2019 08:46
Show Gist options
  • Save malvinstn/4074a6bd6b410af9b7177502a09e6349 to your computer and use it in GitHub Desktop.
Save malvinstn/4074a6bd6b410af9b7177502a09e6349 to your computer and use it in GitHub Desktop.
Sample integration test with FakeAppUpdateManager to validate in app update implementation.
@Test
fun testFlexibleUpdate_Completes() {
// Setup flexible update.
fakeAppUpdateManager.partiallyAllowedUpdateType = AppUpdateType.FLEXIBLE
fakeAppUpdateManager.setUpdateAvailable(2)
ActivityScenario.launch(MainActivity::class.java)
// Validate that flexible update is prompted to the user.
assertTrue(fakeAppUpdateManager.isConfirmationDialogVisible)
// Simulate user's and download behavior.
fakeAppUpdateManager.userAcceptsUpdate()
fakeAppUpdateManager.downloadStarts()
fakeAppUpdateManager.downloadCompletes()
// Perform a click on the Snackbar to complete the update process.
onView(
allOf(
isDescendantOfA(instanceOf(Snackbar.SnackbarLayout::class.java)),
instanceOf(AppCompatButton::class.java)
)
).perform(ViewActions.click())
// Validate that update is completed and app is restarted.
assertTrue(fakeAppUpdateManager.isInstallSplashScreenVisible)
fakeAppUpdateManager.installCompletes()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment