Package com.example.test;
Import Android.support.test.filters.LargeTest;
Import Android.support.test.rule.ActivityTestRule;
Import ANDROID.SUPPORT.TEST.RUNNER.ANDROIDJUNIT4;
Import Org.junit.Rule;
Import Org.junit.Test;
Import Org.junit.runner.RunWith;
Import static Android.support.test.espresso.Espresso.onView;
Import static Android.support.test.espresso.action.ViewActions.click;
Import static Android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
Import static Android.support.test.espresso.action.ViewActions.typeText;
Import static android.support.test.espresso.assertion.ViewAssertions.matches;
Import static android.support.test.espresso.matcher.ViewMatchers.withId;
Import static Android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith (Androidjunit4.class)
@LargeTest
public class Mainactivityinstrumentedtest {
private static final String string_to_be_typed = "Him";
What to write
@Rule
Public activitytestrule<mainactivity> mainactivitytestrule = new Activitytestrule<mainactivity> ( Mainactivity.class);
@Test
public void SayHello () {
Onview (Withid (R.id.edittext)). Perform (TypeText (string_to_be_typed), Closesoftkeyboard ());
Gets the ID of the EditText and writes the value to
Onview (Withtext ("Say hello")). Perform (click ());
Use the text position button of the control and implement the Click action
String Expectedtext = "Hello," + string_to_be_typed + "!";
The correct output content
Onview (Withid (R.id.textview)). Check (Matches (Withtext (Expectedtext)));
Gets the ID of the TextView, which is more consistent than the text on the control
}
}
Use the Espresso test framework for UI testing in an Android studio environment