【问题标题】:What is the difference between ActivityTestRule and IntentTestRuleActivityTestRule 和 IntentTestRule 有什么区别
【发布时间】:2019-12-13 07:15:14
【问题描述】:

在探索测试时,我遇到了 ActivityTestRule 和 IntentTestRule,据我所知,IntentTestRule 是 ActivityTestRule 的扩展,用于 Espresso Intents。

但归根结底,使用这些测试规则的真正目的是什么。

【问题讨论】:

    标签: android testing android-espresso


    【解决方案1】:

    The purpose is:

    在使用@Test 注释的每个测试之前初始化 Espresso-Intents 和 每次测试运行后发布 Espresso-Intents。以下代码 sn -p 是IntentsTestRule 的示例:

    @Rule
    public IntentsTestRule<MyActivity> intentsTestRule =
            new IntentsTestRule<>(MyActivity.class);
    

    Alternatively,

    您可以使用ActivityTestRule 代替IntentsTestRule,然后在 您的 @Before@After 手动调用 Intents.init() 和 分别为Intents.release()

    @Override
    protected void afterActivityLaunched() {
        Intents.init();
        super.afterActivityLaunched();
    }
    
    @Override
    protected void afterActivityFinished() {
        super.afterActivityFinished();
        Intents.release();
    }
    

    And the purpose of Espresso-intents is

    启用对发出的 Intent 的验证和存根 正在测试的应用程序。它类似于 Mockito,但适用于 Android Intents。

    【讨论】:

    • Google GitHub 链接已损坏
    • 完美解释!!
    猜你喜欢
    • 2010-10-02
    • 2011-12-12
    • 2010-09-16
    • 2012-03-14
    • 2012-02-06
    • 2011-02-25
    • 2011-11-22
    • 2015-03-26
    • 2013-08-19
    相关资源
    最近更新 更多