gpt4 book ai didi

android - ActivityTestRule 和 IntentTestRule 有什么区别

转载 作者:太空宇宙 更新时间:2023-11-03 12:46:25 26 4
gpt4 key购买 nike

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

但核心是使用这些测试规则的真正目的是什么。

最佳答案

The purpose is :

to initialize Espresso-Intents before each test annotated with @Test and releases Espresso-Intents after each test run. The following code snippet is an example of an IntentsTestRule:

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

Alternatively ,

you can use ActivityTestRule instead of IntentsTestRule and then in your @Before and @After manually call Intents.init() and Intents.release() respectively.

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

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

And the purpose of Espresso-intents is

to enable validation and stubbing of Intents sent out by the application under test. It’s like Mockito, but for Android Intents.

关于android - ActivityTestRule 和 IntentTestRule 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43064681/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com