Android 自动化测试工具 UIAutomator(一)

emmm,项目需要,所以学习一下很基础的Android测试知识,涉及到了UIAutomator,觉得很好,记录一下。

一、UIAutomator2.0

  1. UIAutomator2.0是android的自动化测试框架。
  2. Espresso(主要单元测试)+ UIAutoamtor2.0(主要UI测试)= ATSL(安卓测试知识库)
  3. 黑盒UI自动化测试套路:通过搜索条件,查找组件,然后操作组件。

二、一个简单测试工程

  1. 新建Android工程
  2. 添加UIAutomator2.0依赖
    在app模块的build.gradle中添加对UIAutomator2.0的依赖,同时将minSdkVersion改为18
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
  1. 在如图所示的地方新建Java测试类
    AndroidTest
  2. 敲代码 First_Try_Test.java
import android.app.Instrumentation;
import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class) //指定使用哪个运行器来运行测试用例
public class First_Try_Test {
    public Instrumentation mInstrumentation;
    public UiDevice mUiDevice;

    @Before //用例运行之前一定会运行的
    public void setUp(){
        //实例化对象
        mInstrumentation = InstrumentationRegistry.getInstrumentation();
        mUiDevice = UiDevice.getInstance(mInstrumentation);
    }
    /**以上可以为固定的代码套路**/

    @Test //表明正式测试用例
    public void DemoTest()throws RemoteException {
        mUiDevice.pressRecentApps();//按一下最近任务键
    }

}
  1. 运行测试用例,右击DemoTest,选择如图所示按钮
    AndroidTest2
  2. 生成测试报告
    androidTest
    androidTest4

三、效果(模拟点击最近任务栏)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值