I use Espresso to write UI tests for my Android application and would like to mock http requests using MockWebServer. I need to make fun of authentication responses and sign the user before running the tests.
Is there a way to force the application to use mockwebserver so that it will execute the actual requests, I can use respones installed on mockwebserver.
So far, I:
public class AuthenticationTest { @Rule public ActivityTestRule<Authentication> mActivityTestRule = new ActivityTestRule<>(Authentication.class); private Authentication activity; private MockWebServer server; @Before public void signin() throws Exception { server = new MockWebServer(); server.start(); activity = mActivityTestRule.getActivity(); MyApplication.State state = activity.getState(); String serverUrl = server.url("/").toString();
source share