zoukankan      html  css  js  c++  java
  • 在Android Studio环境下使用ESPRESSO 测试框架进行UI测试

    1.首先,在后缀为AndroidTest的文件夹内建立一个MainActivityInstrumentedTest的Java文件,

    package com.example.pj.git;

    import android.support.test.filters.LargeTest;
    import android.support.test.rule.ActivityTestRule;
    import android.support.test.runner.AndroidJUnit4;
    import android.view.View;

    import org.hamcrest.Matcher;
    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;

    /**
    * Created by pj on 2017/3/15.
    */
    @RunWith(AndroidJUnit4.class)
    @LargeTest
    public class MainActivityInstrumentationTest {
    private static final String STRING_TO_BE_TYPED = "Peter";

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<MainActivity>(MainActivity.class);

    @Test
    public void sayHello() {
    onView(withId(R.id.et)).perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
    onView(withText("Say hello!")).perform(click());
    String expectedText = "Hello," + STRING_TO_BE_TYPED + "!";
    onView(withId(R.id.tv)).check(matches(withText(expectedText)));
    }
    }

    2.然后在模拟器上运行MainActivityInstrumentedTest,如果运行成功会提示

    如果运行失败会提示

    
    
  • 相关阅读:
    360给腾讯造的盗梦空间
    C 语言 运算符优先级
    CorelDraw, Adobe Illustrator 转换到 Photoshop 形状路径
    用户体验经典解释
    禁用Windows XP的自动播放功能
    ObjectiveC ARC下的内存管理(一)
    ARC下的内存管理(二)对象及成员的引用关系
    天天撞墙
    PS: 操作不实时显示的解决办法
    摩托罗拉 Milestone新手刷机教程
  • 原文地址:https://www.cnblogs.com/pujun/p/6568153.html
Copyright © 2011-2022 走看看