Last active
March 13, 2019 18:28
-
-
Save johngorithm/4263ed160bb83136003a277024db3e7d 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
@Test | |
public void testTeachersAreDisplayed() throws IOException { | |
/** | |
* Setting up mockWebServer at localhost:9900. | |
*/ | |
MockWebServer server = new MockWebServer(); | |
// start the server at port 9900 | |
server.start(9900); | |
/** | |
* Get the target application context during testing and cast onto the TestDemoApplication | |
*/ | |
TestDemoApplication testApp = (TestDemoApplication) InstrumentationRegistry.getTargetContext().getApplicationContext(); | |
// Set the base url of the test app using the url of the mocked local server | |
testApp.setBaseUrl(server.url("/").toString()); | |
// Enqueue the response you want the server to respond with when querried in the course to this test. | |
server.enqueue(new MockResponse().setBody(SUCCESS_RESPONSE)); | |
// LAUNCH ACTIVITY | |
mainActivityTestRule.launchActivity(null); | |
// UI testing | |
onView(withText("John Doe")).check(matches(isDisplayed())); | |
onView(withText("William Smith")).check(matches(isDisplayed())); | |
// Shut down the server when done with testing | |
server.shutdown(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment