Skip to content

Commit

Permalink
Add basic UI tests, testing drawer behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
tiembo committed Sep 14, 2018
1 parent 1c57114 commit c877035
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ dependencies {

implementation "com.crashlytics.sdk.android:crashlytics:${versions.crashlytics}"
implementation "com.google.firebase:firebase-core:${versions.firebase}"

testImplementation project(':test_shared')
testImplementation "android.arch.core:core-testing:${versions.lifecycle}"
testImplementation "com.nhaarman:mockito-kotlin:${versions.mockito_kotlin}"
testImplementation "junit:junit:${versions.junit}"

androidTestImplementation project(':test_shared')
androidTestImplementation "android.arch.core:core-testing:${versions.lifecycle}"
androidTestImplementation "com.android.support.test:runner:${versions.test_runner}"
androidTestImplementation "com.android.support.test:rules:${versions.test_rules}"
androidTestImplementation "com.android.support.test.espresso:espresso-contrib:${versions.espresso}"
androidTestImplementation "com.android.support.test.espresso:espresso-core:${versions.espresso}"
androidTestImplementation "com.android.support.test.uiautomator:uiautomator-v18:${versions.ui_automator}"
androidTestImplementation "com.nhaarman:mockito-kotlin:${versions.mockito_kotlin}"
androidTestImplementation "org.mockito:mockito-android:${versions.mockito}"
androidTestImplementation "org.mockito:mockito-core:${versions.mockito}"
}

// Must be applied after dependencies. See https://stackoverflow.com/a/38018985
Expand Down
73 changes: 73 additions & 0 deletions app/src/androidTest/java/io/plaidapp/ui/HomeActivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2018 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.plaidapp.ui

import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.contrib.DrawerMatchers.isClosed
import android.support.test.espresso.contrib.DrawerMatchers.isOpen
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.rule.ActivityTestRule
import android.support.test.uiautomator.UiDevice
import android.view.Gravity
import io.plaidapp.R
import org.junit.Rule
import org.junit.Test

class HomeActivityTest {

@Rule
@JvmField
var activityTestRule = ActivityTestRule(HomeActivity::class.java)

@Test
fun drawerClosedOnStartup() {
// Given that the app is not launched

// When the app is first launched

// Then the drawer should be closed
onView(withId(R.id.drawer)).check(matches(isClosed(Gravity.END)))
}

@Test
fun pressFilterButtonOpensDrawer() {
// Given that the drawer is closed
onView(withId(R.id.drawer)).check(matches(isClosed(Gravity.END)))

// When the filter button is pressed
onView(withId(R.id.menu_filter)).perform(click())

// Then the drawer should be opened
onView(withId(R.id.drawer)).check(matches(isOpen(Gravity.END)))
}

@Test
fun drawerStaysOpenAfterRotation() {
// Given that the drawer is open
onView(withId(R.id.menu_filter)).perform(click())
onView(withId(R.id.drawer)).check(matches(isOpen(Gravity.END)))

// When rotating the device
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).setOrientationLeft()

// Then the drawer should stay open after rotation
onView(withId(R.id.drawer)).check(matches(isOpen(Gravity.END)))
}
}
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ buildscript {
'room' : '1.1.1',
'supportLibrary' : '27.1.1',
'test_rules' : '1.0.2',
'test_runner' : '1.0.2'
'test_runner' : '1.0.2',
'ui_automator' : '2.1.3'
]
ext.names = [
'applicationId': 'io.plaidapp'
Expand Down

0 comments on commit c877035

Please sign in to comment.