Skip to content

Instantly share code, notes, and snippets.

@oznus
Last active August 15, 2017 18:13
Show Gist options
  • Save oznus/4022ebfbebd4acfb91a213648ec5a819 to your computer and use it in GitHub Desktop.
Save oznus/4022ebfbebd4acfb91a213648ec5a819 to your computer and use it in GitHub Desktop.
@RunWith(AndroidJUnit4.class)
public class MainActivityTests {
@Rule
public ActivityTestRule<MainActivity> activityRule =
new ActivityTestRule<>(MainActivity.class);
@Before
public void init() {
//getting the application class
MyAppApplication myApp = (MyAppApplication) InstrumentationRegistry
.getInstrumentation()
.getTargetContext()
.getApplicationContext();
//building the app component with the mocked module
MyAppComponent mockedComponent = DaggerMyAppComponent.builder()
.myAppModule(new MyAppModuleMock()).build();
//setting the component with the mocked module as the main app component
myApp.setMyAppComponent(mockedComponent);
}
@Test
public void getUsers() throws Exception {
List<Object> users = activityRule.getActivity().getUsersFromNetwork();
/// those are the mocked users....
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment