public void testProfileActivityLoadsCorrectData() throws Throwable { TestUtils.setupSocializeOverrides(true, true); Instrumentation.ActivityMonitor monitor = TestUtils.setUpActivityMonitor(this, ProfileActivity.class); final User dummy = new User(); dummy.setId(69L); dummy.setFirstName("foo"); dummy.setLastName("bar"); SocializeUserUtils userUtils = new SocializeUserUtils() { @Override public void getUser(Context context, long id, UserGetListener listener) { listener.onGet(dummy); } @Override public User getCurrentUser(Context context) { return dummy; } }; SocializeAccess.setUserUtilsProxy(userUtils); // Ensure facebook is enabled ConfigUtils.getConfig(getContext()).setFacebookAppId("1234567890"); ConfigUtils.getConfig(getContext()) .setTwitterKeySecret( "U18LUnVjULkkpGoJ6CoP3A", "RiIljnFq4RWV9LEaCM1ZLsAHf053vX2KyhJhmCOlBE"); UserUtils.showUserSettings(TestUtils.getActivity(this)); Activity waitForActivity = monitor.waitForActivityWithTimeout(5000); assertNotNull(waitForActivity); // Check that the user's name is displayed assertTrue(TestUtils.lookForText(waitForActivity, "foo", 10000)); assertTrue(TestUtils.lookForText(waitForActivity, "bar", 10000)); waitForActivity.finish(); }
@Test public void goUserPageFromComment() { setupMockServer(null); activityRule.launchActivity(intent); TimingIdlingResource idlingResource = new TimingIdlingResource(3000); // wait dummy network operation Espresso.registerIdlingResources(idlingResource); onView(withId(R.id.comment_parent)).perform(clickComment()); Espresso.unregisterIdlingResources(idlingResource); Instrumentation.ActivityMonitor receiverActivityMonitor = InstrumentationRegistry.getInstrumentation() .addMonitor(UserActivity.class.getName(), null, false); Activity activity = receiverActivityMonitor.waitForActivityWithTimeout(1000); assertEquals("Launched Activity is not UserActivity", UserActivity.class, activity.getClass()); onView(withText("¡! Nature B■x !¡")).check(matches(isDisplayed())); pressBack(); SystemClock.sleep(2000); }
@MediumTest public void testSendMessageToReceiverActivity3() { final ImageButton sendToReceiverButton = (ImageButton) getActivity().findViewById(R.id.imageButton); final EditText et = (EditText) getActivity().findViewById(R.id.First_Name); getInstrumentation() .runOnMainSync( new Runnable() { @Override public void run() { et.setText("hello"); } }); Instrumentation.ActivityMonitor receiverActivityMonitor = getInstrumentation().addMonitor(FullNameActivity.class.getName(), null, false); TouchUtils.clickView(this, sendToReceiverButton); FullNameActivity receiverActivity = (FullNameActivity) receiverActivityMonitor.waitForActivityWithTimeout(2000); assertNull("ReceiverActivity is null", receiverActivity); getInstrumentation().removeMonitor(receiverActivityMonitor); }
public void testEditTweet() throws Exception { // When you call getActivity() android will start up the app and the activity Activity myActivity = getActivity(); LonelyTwitterActivity activity = (LonelyTwitterActivity) myActivity; // Reset the app to known state activity.getTweets().clear(); // Add a tweet using UI bodyText = activity.getBodyText(); activity.runOnUiThread( new Runnable() { public void run() { bodyText.setText("So Lonely"); } }); getInstrumentation().waitForIdleSync(); // Activate OnClickListener saveButton = activity.getSaveButton(); activity.runOnUiThread( new Runnable() { public void run() { saveButton.performClick(); } }); getInstrumentation().waitForIdleSync(); // Make sure the tweet was actually saved oldTweetsList = activity.getOldTweetsList(); Tweet tweet = (Tweet) oldTweetsList.getItemAtPosition(0); assertEquals("So Lonely", tweet.getText()); // Ensure the Tweet Editor activity has begun // https://developer.android.com/training/activity-testing/activity-functional-testing.html // Set up an ActivityMonitor Instrumentation.ActivityMonitor receiverActivityMonitor = getInstrumentation().addMonitor(EditTweetActivity.class.getName(), null, false); // Validate that ReceiverActivity is started // They Clicked Here // ----------------- // Click on The Tweet To Edit activity.runOnUiThread( new Runnable() { public void run() { View v = oldTweetsList.getChildAt(0); oldTweetsList.performItemClick(v, 0, v.getId()); } }); getInstrumentation().waitForIdleSync(); // ----------------- EditTweetActivity receiverActivity = (EditTweetActivity) receiverActivityMonitor.waitForActivityWithTimeout(1000); assertNotNull("EditTweetActivity is null", receiverActivity); assertEquals( "Monitor for ReceiverActivity has not been called", 1, receiverActivityMonitor.getHits()); assertEquals("Activity is of wrong type", EditTweetActivity.class, receiverActivity.getClass()); // Remove the ActivityMonitor getInstrumentation().removeMonitor(receiverActivityMonitor); // test that the editor starts up with the right tweet textbox = receiverActivity.getTextbox(); String text = textbox.getText().toString(); assertEquals("So Lonely", text); // test that it can be edited activity.runOnUiThread( new Runnable() { public void run() { textbox.performClick(); textbox.append("!"); } }); getInstrumentation().waitForIdleSync(); text = textbox.getText().toString(); assertEquals("So Lonely!", text); // test that we can push a save button for that tweet saveEdit = receiverActivity.getSaveEdit(); activity.runOnUiThread( new Runnable() { public void run() { saveEdit.performClick(); } }); getInstrumentation().waitForIdleSync(); // test that the new modified tweet was saved myActivity = getActivity(); activity = (LonelyTwitterActivity) myActivity; assertEquals("So Lonely!", activity.getTweets().get(0).getText()); // test that the new modified tweet is displayed on previous activity assertEquals("So Lonely!", activity.getTweets().get(0).getText()); // Clean up all activities at the end of the test receiverActivity.finish(); activity.finish(); }