How to write tests for deep links in Android?

前端 未结 2 502
野的像风
野的像风 2020-12-30 11:01

I would like to write tests for Android app with deep link cases using UI testing framework (Espresso) - launch app using only ACTION_VIEW intent and check all views on open

相关标签:
2条回答
  • 2020-12-30 11:40
    @Rule
    public ActivityTestRule<AppLauncherActivity> activityRule = new ActivityTestRule<>(AppLauncherActivity.class, false, false);
    

    There are multiple constructors for creating an ActivityTestRule. The third one is launchActivity. Set it to false as shown above because you manually start that activity afterwards with activityRule.launchActivity(intent). This should prevent it from starting twice

    0 讨论(0)
  • 2020-12-30 11:48

    I found one option - just added deep link opening parameters for existed intent and use standard activity launch:

    @Rule
    public ActivityTestRule<AppLauncherActivity> activityRule = new ActivityTestRule<AppLauncherActivity>(AppLauncherActivity.class){
        @Override protected Intent getActivityIntent() {
            Intent intent = super.getActivityIntent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("myapp://search/777"));
            return intent;
        }
    };
    
    0 讨论(0)
提交回复
热议问题