android - 我似乎无法弄清楚如何测试 BottomBar Navigation
问题描述
我正在使用材料 BottomNavigationView 并且正在尝试测试导航:
测试:
@Test //fails
fun navigationMenu_contractClicked_openContractFragment() {
Espresso.onView(ViewMatchers.withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.contractFragment))
Espresso.onView(ViewMatchers.withId(R.id.constraint_contract_overview))
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/raisingBlack"
app:itemBackground="@color/raisingBlack"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
但我得到了这个错误:
androidx.test.espresso.PerformException:在“目标设备上启用动画或过渡”视图上执行“单击带有 id 的菜单项”时出错。
由于我对 android 和 kotlin 很陌生,所以我完全不知道该怎么做才能解决这个问题。
解决方案
由于它们引入的视觉状态延迟,Espresso 不适用于动画。您需要禁用设备上的动画。首先,启用开发者选项:
打开设置应用程序。滚动到底部并选择关于手机。滚动到底部并点击内部版本号 7 次。返回上一个屏幕以在底部附近找到开发人员选项。从设置应用程序访问开发人员选项,然后在绘图部分下,将以下所有选项切换为动画关闭:
窗口动画比例
过渡动画比例
动画师持续时间比例
推荐阅读
- c# - ASP MVC:创建表达式
> 以编程方式表达 - java - 写了一段黄瓜代码并试图在 Maven 中执行,浏览器被调用但它没有在浏览器中给出 URL
- java - 比较目录中的 jar 证书
- sparql - 查找在 SPARQL 查询中应用的直接属性
- wordpress - wp 多站点:添加新的超级管理员
- reactjs - Webpack 3 + Sass Loader:不能将 scss 用作模块
- c# - Visual Studio 2017 - 无法将“ReportViewer”添加到“Windows 窗体”
- r - 根据数据集的行值应用规则
- java - 使用扫描仪根据用户输入创建数组
- openstack-keystone - 禁止:您无权执行请求的操作