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))); } }
时间: 2024-10-15 10:16:29