Android单元测试框架-Espresso

    xiaoxiao2021-03-25  100

    导入框架,在gradle中添加配置(一般默认创建项目就有这个了) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) 创建TEST类文件 在当前类文件鼠标右键在TEST类文件中指定测试类 例如 @Rule public ActivityTestRule mActivityRule = new ActivityTestRule(MainActivity.class); 随意创建方法,但是方法得打上注解@Test 例如 @Test public void login1() {

    语法详解

    获取控件案例

    通过ID获取控件 onView(withId(R.id.et_username))通过文本内容获取控件 onView(withText("About"))

    使用案例

    控件输入文本信息

    perform(执行的具体操作)下面按案例中放的是键入文本cree1 * onView(withId(R.id.et_username)).perform(typeText("cree1"));

    控件点击事件

    click()为点击操作 * onView(withId(R.id.button)).perform(click());

    打开菜单事件 * openActionBarOverflowOrOptionsMenu(getInstrumentation().getContext());

    检查控件内的文本是否为ActionMode1 * onView(withId(R.id.status)).check(matches(withText("ActionMode1")));

    针对控件右滑操作 * onView(withId(R.id.pager)).perform(swipeLeft());

    检查控件是显示的 * onView(withId(R.id.error_text)).check(matches(isDisplayed()));

    转载请注明原文地址: https://ju.6miu.com/read-9499.html

    最新回复(0)