如何为测试 Firebase Dynamic 构建单元测试 Link

How to build a unit test for test Firebase Dynamic Link

我想自动执行消费 Firebase Dynamic Link.

的测试

该应用程序对我从电子邮件中打开的任何有效动态 link 响应良好,但要对其进行测试,我需要从我的测试代码中打开 url。

我该怎么做?加载 url 不会触发 Android 打开我的应用程序。

解决方案通过使用 ActivityTestRule,如下所示:

@RunWith(AndroidJUnit4.class)
public class TestYard {

    //assign these test rule to the test
    @Rule
    public ActivityTestRule testRule = new ActivityTestRule(false,false); 


    @Test
    public void testDynamicLink() {

        //Dynamic link url
        String url = "https://....app.goo.gl/...";

        //create intent
        Intent intent = new Intent (Intent.ACTION_VIEW);
        intent.setData (Uri.parse(url));

        //launch activity with the url as intent. Should work exactly as open from the email generated by Firebase invite function.
        testRule.launchActivity(intent);
    }
}

检查如何准备应用 here