0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ナビゲーションドローワーのUIテスト

Last updated at Posted at 2019-07-09

EspressoでUIテストを実施していて、ふと、ナビゲーションドローワーがある場合はどうなるんだろうと思い、やってみました。

dependencyの追加

ナビゲーションドローワーのアクションはespresso-contribのライブラリに入っているので追加しました。
その時、バージョン違いでコンフリクトが起こったので、重複しているものは除外します。

build.gradle(app)
androidTestImplementation ('com.android.support.test.espresso:espresso-contrib:3.0.2') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'support-compat'
        exclude group: 'com.android.support', module: 'support-core-utils'
    }

これでボタンクリックと同じようにナビゲーションドローワーを開くアクションが使えるようになります。

テストの記載

NavigatinViewは下記になります。

activity_main.xml
<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />
MainActivityTest
    @Test
    fun navigationMenu_updatetime_exist() {
        onView(ViewMatchers.withId(R.id.drawer_layout)).perform(DrawerActions.open())
        Thread.sleep(1500)
        onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_slideshow))
        Thread.sleep(1500)
        onView(ViewMatchers.withId(R.id.updateTimeLabel)).check(matches(not(doesNotExist())))
    }

ナビゲーションドローワーを開くアクションはDrawerActions.open()になります。
開いたら、NavigationViewActions.navigateTo(R.id.nav_slideshow)の部分で、開いたドローワーに存在するメニューをタップしています。

実際にテストしてみて、思ったより画面の操作は担保できるなあと感じました。

参照

[Espresso] NavigationViewをNavigationViewActionsで操作してみようの話

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?