您当前的位置: 首页 >  自动化

新一代螺丝工

暂无认证

  • 5浏览

    0关注

    22博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Android自动化测试技术——Espresso的使用

新一代螺丝工 发布时间:2022-09-14 22:31:57 ,浏览量:5

配置 修改设置

先启用开发者选项,再在开发者选项下,停用以下三项设置:

  • 窗口动画缩放
  • 过渡动画缩放
  • Animator 时长缩放
添加依赖

app/build.gradle文件中添加依赖

androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'

app/build.gradle文件中的android.defaultConfig中添加

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

注意:上面的依赖只能实现基本功能,如果你想使用所有的功能,则按下面的配置:

所有依赖

    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.ext:truth:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'

下面调用的方法如onView()等都是静态方法,可以通过import static XXX来直接调用,所有需要导入的静态方法如下:

import static androidx.test.espresso.Espresso.*;
import static androidx.test.espresso.action.ViewActions.*;
import static androidx.test.espresso.assertion.ViewAssertions.*;
import static androidx.test.espresso.intent.Intents.intended;
import static androidx.test.espresso.intent.Intents.intending;
import static androidx.test.espresso.intent.matcher.ComponentNameMatchers.*;
import static androidx.test.espresso.intent.matcher.IntentMatchers.*;
import static androidx.test.espresso.matcher.ViewMatchers.*;
import static androidx.test.ext.truth.content.IntentSubject.assertThat;
Api组件

常用Api组件包括:

  • Espresso - 用于与视图交互(通过 onView() 和 onData())的入口点。此外,还公开不一定与任何视图相关联的 API,如 pressBack()。
  • ViewMatchers - 实现 Matcher
关注
打赏
1663165755
查看更多评论
立即登录/注册

微信扫码登录

0.1227s