Last active
August 15, 2017 18:13
-
-
Save oznus/4022ebfbebd4acfb91a213648ec5a819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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