Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ActivityTestRule and IntentTestRule

while exploring Testing I came across ActivityTestRule and IntentTestRule as far as i have understood is this that IntentTestRule are an extension of ActivityTestRule and are used in Espresso Intents.

But at the core what is the real purpose of using these testing rules.

like image 638
cammando Avatar asked Mar 28 '17 08:03

cammando


1 Answers

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.

like image 194
albodelu Avatar answered Sep 23 '22 17:09

albodelu