2017-11-30 7 views
1

Ich möchte Tests für alle meine Deep-Links hinzufügen, um sie zu starten und sehen, ob die erforderliche Aktivität gestartet wird und behaupten, was auf dieser Aktivität angezeigt wird.So testen Sie DeepLinks mit espresso

Wie kann ich es tun?

bearbeiten

I-Tests am Ende nur die DeepLinking wie https://medium.com/@singwai/testing-deep-linking-with-espresso-and-burst-5e1bdb3c5e29 sagt übereinstimmen.

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") 
    } 
} 

Dann überprüfe ich, ob es Aktivitäten gibt, die meine Urls lösen, und testen Sie jede Aktivität auf einem eigenen Test.

+0

ich bereits auf gleiche Frage hier antwortete: https://stackoverflow.com/questions/44074173/automating-deep-linking-using-android-espresso/47813474 # 47813474 hoffe es hilft! –

+0

@Caipivara hast du das funktioniert? –

+0

@ JohnO'Reilly none – Caipivara

Antwort

1

sollte in der Lage sein, etwas zu verwenden, wie folgt vor:

launchActivityWithIntent(getActivity().getPackageName(), 
     YourActivityThatHandlesDeepLink.class, 
     new Intent(Intent.ACTION_VIEW).setData(Uri.parse(link))); 
+0

Wer ist der Besitzer dieser Funktion 'launchActivityWithIntent'? – Caipivara

+0

@Caipivara https://developer.android.com/reference/android/test/InstrumentationTestCase.html –

+0

Es funktioniert, danke. Am Ende habe ich stattdessen 'ActivityTestRule' und' rule.launchActivity (Intent (Intent.ACTION_VIEW) .setData (Uri.parse (deepLink))) '' verwendet. – Caipivara