用途:为 Android 应用生成 Espresso UI 测试代码,默认使用 Kotlin,也可用 Java。Espresso 在应用进程内运行,适合快速、可靠的界面测试。
主要能力:覆盖基础测试结构(AndroidJUnit4、ActivityScenarioRule)、ViewMatchers 查找元素(withId、withText、withContentDescription、withHint、allOf、RecyclerViewActions、isDescendantOfA)、ViewActions 执行操作(click、longClick、typeText、replaceText、clearText、closeSoftKeyboard、scrollTo、swipe 系列、pressBack)、ViewAssertions 校验状态(isDisplayed、withText、isEnabled、isChecked、hasErrorText、doesNotExist),以及 IdlingResources 处理异步操作,并给出自定义 NetworkIdlingResource 示例。还包含反模式对照(如用 IdlingResources 替代 Thread.sleep、优先 withId、单屏隔离测试、typeText 后关闭软键盘)。
使用方式:在 build.gradle 中配置 testInstrumentationRunner 为 androidx.test.runner.AndroidJUnitRunner,并添加 espresso-core、espresso-contrib、espresso-intents、test:runner、test:rules、test.ext:junit 等 androidTestImplementation 依赖。本地执行使用 ./gradlew connectedAndroidTest,可指定测试类或设备。云端执行需先构建 APK 与测试 APK,再上传至 LambdaTest 并通过 Espresso 构建 API 在真机运行。
适用场景:Android 应用的界面回归与功能验证,本地模拟器或真机设备农场均可。
限制:资料未提供具体收费、价格与效果数据;云端执行依赖 LambdaTest 账号与凭据,需自行准备 APK 与测试 APK。