Issue
I want to add tests for all my deep links, to launch them and see if the needed activity is launched and assert over what is showed on that activity.
How can I do it?
Edit
I ended up testing just the deep linking matching like https://medium.com/@singwai/testing-deep-linking-with-espresso-and-burst-5e1bdb3c5e29 says.
In kotlin:
@Throws(Exception::class)
fun test_deepLink_isResolvedBy(url: String, canonicalActivityName: String) {
val appContext = InstrumentationRegistry.getTargetContext()
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
val resolvedActivities =
appContext.packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)
val resolverActivityMissing = resolvedActivities.none {
it.activityInfo.packageName == appContext.packageName &&
it.activityInfo.name == canonicalActivityName
}
if (resolverActivityMissing) {
fail("$url is not resolved for $canonicalActivityName")
}
}
Then I check if there are activities that resolve my urls, and test each activity on its own test.
Solution
Should be able to use something like following:
launchActivityWithIntent(getActivity().getPackageName(),
YourActivityThatHandlesDeepLink.class,
new Intent(Intent.ACTION_VIEW).setData(Uri.parse(link)));
Answered By - John O'Reilly
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.