Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
Last active April 17, 2023 14:07
Show Gist options
  • Star 125 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save JakeWharton/1c2f2cadab2ddd97f9fb to your computer and use it in GitHub Desktop.
Save JakeWharton/1c2f2cadab2ddd97f9fb to your computer and use it in GitHub Desktop.
A JUnit @rule which launches an activity when your test starts. Stop extending gross ActivityInstrumentationBarfCase2!
@RajeshBatth
Copy link

Hi Jake,
Is there any means by which i can get the reference of Activity before its onCreate is called?
I want this because i want to inject mocks from tests into Activity.

@IgorGanapolsky
Copy link

Android testing support library already includes their ActivityTestRule. Why do we need this ActivityRule?

@JakeWharton
Copy link
Author

@IgorGanapolsky Mine came first.

@stefanlam88
Copy link

hi all, need your expertise here. I m not sure why my JUnit4.class is in red color. I already sync gradle

/* JUnit4 & Espresso */
androidTestCompile 'com.android.support.test:runner:0.3'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'

but not working?any 1 know why?

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