首页 > 代码库 > Say Hello的测试类及结果

Say Hello的测试类及结果

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)));
    }
}

技术分享

Say Hello的测试类及结果