Uiautomator2.0+junit4

1.打开androidStudio 创建Android项目  最后一步选择empty

2.在build.gradle(module:app)的dependencies{}里加上以下

androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
3.修改dependencies v7版本号 可以不改但可能会报错
compile 'com.android.support:appcompat-v7:23.0.1'
4.在项目的java目录下 有两个目录 同名 其中一个有(androidTest)
在这个Test目录下 建一个类

public class ApplicationTest  {


    public static String TAG="lisa";
    public  UiDevice device=null;
    public Context mContext = null;

    @BeforeClass
    public static void beforeClass(){
        Log.d(TAG, "BeforeClass");
    }

    @AfterClass
    public static void afterClass(){
        Log.d(TAG, "AfterClass");
    }

    @Before
    public void before() throws RemoteException {
        Log.d(TAG, "Before");
        device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());  
        mContext = InstrumentationRegistry.getContext();
        device.wakeUp();
    }

    @After
    public void after(){
        Log.d(TAG, "After");
    }

    @Test
    public void test001() {
        Log.d(TAG, "test001");
        assertEquals(1,1);
    }

    @Test
    public void test002() {
        Log.d(TAG, "test002");
    }
}

5.在工程目录下terminal执行gradle cC

6.如果此时连接收集 就会看到手机屏幕点亮 

device.wakeUp();被执行

7./Users/lisa/Codes/UiTestProj/app/build/reports/androidTests/connected/index.html 为执行详细信息 

8.由于向下兼容 uiautomator1.0的代码也可以执行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值