Skip to content

Instantly share code, notes, and snippets.

@grumpyshoe
Created November 22, 2016 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grumpyshoe/fdcddeed2c70c0b2b0d69428ce83ecca to your computer and use it in GitHub Desktop.
Save grumpyshoe/fdcddeed2c70c0b2b0d69428ce83ecca to your computer and use it in GitHub Desktop.
Espresso: How to add intent Extras/Bundle to IntentsTestRule
@Rule
public IntentsTestRule<MainActivity> mTestRule = new IntentsTestRule<MainActivity>(MainActivity.class){
@Override
protected Intent getActivityIntent() {
Context targetContext = InstrumentationRegistry.getInstrumentation()
.getTargetContext();
Intent result = new Intent(targetContext, MainActivity.class);
result.putExtra("Name", "Value");
return result;
}
};
@nurisezginspexco
Copy link

nurisezginspexco commented Feb 16, 2017

@Test
public void should_Sample(){
    Intents.release();
    Intent intent = new Intent();
    intent.putExtra("Name", "Value");
    mActivityTestRule.launchActivity(intent);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment