用户登录界面测试,在新包里新建一个测试类如图
测试代码如下
1 public class AndroidTest { 2 private static final String a = "peter"; 3 @Rule 4 public ActivityTestRule<MainActivity> mActivityRule 5 = new ActivityTestRule<MainActivity>(MainActivity.class); 6 7 @Test 8 public void sayHello() { 9 10 onView(withId(R.id.editText)). perform(typeText(a), closeSoftKeyboard()); 11 12 onView(withText("Say hello!")).perform(click()); 13 14 String expectedText = "Hello, " + a + "!"; 15 16 onView(withId(R.id.textView)).check(matches(withText(expectedText))); 17 } 18 }
测试过程及结果
通过则为