public class MainActivityInstrumentationTest {
private static final String STRING_TO_BE_TYPED = "peter";
@Rule
public ActivityTestRule<MainActivity> mainActivityRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void sayHello(){
onView(withId(R.id.name)).perform(typeText(STRING_TO_BE_TYPED), ViewActions.closeSoftKeyboard());
onView(withText("SAY HELLO")).perform(click());
String expectedText = "Hello,"+STRING_TO_BE_TYPED+"!";
onView(withId(R.id.text)).check(matches(withText(expectedText)));
}
}
![](https://images2015.cnblogs.com/blog/1118740/201703/1118740-20170317131914182-777126502.png)