安卓UI测试(基于android studio环境 espresso框架)


用户登录界面测试,在新包里新建一个测试类如图

 

测试代码如下


 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 }

 

测试过程及结果

 

 通过则为

 


posted @ 2017-03-17 21:08  SilentXZP  阅读(183)  评论(0编辑  收藏  举报