Permalink
Browse files

Adds basic Espresso tests

Change-Id: I714c47f1639b61de38adf6e80477f965a8629d91
  • Loading branch information...
JoseAlcerreca committed May 31, 2018
1 parent 6190046 commit beb15c5fa52363ce05d8fd788e1cdb7803a1f5bc
Showing with 792 additions and 121 deletions.
  1. +4 −4 androidTest-shared/build.gradle
  2. +6 −5 build.gradle
  3. +4 −0 mobile/build.gradle
  4. +0 −35 mobile/src/androidTest/java/com/google/samples/apps/iosched/ExampleInstrumentedTest.kt
  5. +52 −0 mobile/src/androidTest/java/com/google/samples/apps/iosched/tests/FixedTimeRule.kt
  6. +42 −0 mobile/src/androidTest/java/com/google/samples/apps/iosched/tests/SetPreferencesRule.kt
  7. +37 −0 mobile/src/androidTest/java/com/google/samples/apps/iosched/tests/SyncTaskExecutorRule.kt
  8. +78 −0 mobile/src/androidTest/java/com/google/samples/apps/iosched/tests/ui/InfoTest.kt
  9. +68 −0 mobile/src/androidTest/java/com/google/samples/apps/iosched/tests/ui/MapTest.kt
  10. +217 −0 mobile/src/androidTest/java/com/google/samples/apps/iosched/tests/ui/ScheduleTest.kt
  11. +104 −0 mobile/src/androidTest/java/com/google/samples/apps/iosched/tests/ui/SessionDetailTest.kt
  12. +9 −5 mobile/src/main/java/com/google/samples/apps/iosched/ui/schedule/filters/EventFilterView.kt
  13. +11 −20 mobile/src/main/java/com/google/samples/apps/iosched/ui/schedule/filters/ScheduleFilterFragment.kt
  14. +22 −13 mobile/src/main/java/com/google/samples/apps/iosched/ui/signin/SignInViewModelDelegate.kt
  15. +10 −0 mobile/src/main/java/com/google/samples/apps/iosched/widget/BottomSheetBehavior.kt
  16. +4 −4 mobile/src/main/res/layout/include_agenda_contents.xml
  17. +0 −1 shared/src/main/java/com/google/samples/apps/iosched/shared/data/NetworkConferenceDataSource.kt
  18. +1 −1 shared/src/main/java/com/google/samples/apps/iosched/shared/util/TimeUtils.kt
  19. +105 −0 shared/src/staging/java/com/google/samples/apps/iosched/shared/data/FakeConferenceDataSource.kt
  20. +0 −28 shared/src/staging/java/com/google/samples/apps/iosched/shared/data/OfflineConferenceDataSource.kt
  21. +15 −1 shared/src/staging/java/com/google/samples/apps/iosched/shared/di/ServiceBindingModule.kt
  22. +3 −4 shared/src/staging/java/com/google/samples/apps/iosched/shared/di/SharedModule.kt
@@ -25,7 +25,7 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
@@ -34,7 +34,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$rootProject.kotlinVersion"
// Architecture Components
implementation "android.arch.lifecycle:extensions:$rootProject.lifecycleVersion"
implementation "android.arch.lifecycle:livedata:$rootProject.lifecycleVersion"
implementation "android.arch.lifecycle:viewmodel:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel:$rootProject.lifecycleVersion"
}
View
@@ -27,18 +27,18 @@ buildscript {
versionCodeMobile = versionCodeBase + 3
// SDK and tools
compileSdkVersion = 'android-P'
compileSdkVersion = 28
minSdkVersion = 21
minTvSdkVersion = 21 // TV was introduced with Lollipop, min SDK should be 21.
targetSdkVersion = 27
targetSdkVersion = 28
// At this time, there isn't a device (or emulator) that supports 27.
compileWearSdkVersion = 'android-P'
compileWearSdkVersion = 28
minWearSdkVersion = 23
targetWearSdkVersion = 27
targetWearSdkVersion = 28
// App dependencies
androidGradlePluginVersion = '3.2.0-alpha16'
androidGradlePluginVersion = '3.2.0-alpha17'
appcompatVersion = '1.0.0-alpha1'
browserVersion = '1.0.0-alpha1'
constraintLayoutVersion = '1.1.0'
@@ -73,6 +73,7 @@ buildscript {
mockitoKotlinVersion = "1.5.0"
okhttpVersion = "3.10.0"
pageIndicatorVersion = "1.3.0"
rulesVersion = '1.1.0-alpha1'
runnerVersion = '1.1.0-alpha1'
threetenabpVersion = "1.0.5"
threetenbpVersion = "1.3.6"
View
@@ -102,6 +102,8 @@ android {
lintOptions {
disable "InvalidPackage", "MissingTranslation"
}
testBuildType "staging"
}
dependencies {
@@ -150,7 +152,9 @@ dependencies {
// Instrumentation tests
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion"
androidTestImplementation "androidx.test:runner:$rootProject.runnerVersion"
androidTestImplementation "androidx.test:rules:$rootProject.rulesVersion"
// Local unit tests
testImplementation "junit:junit:$rootProject.junitVersion"

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,52 @@
/*
* Copyright 2018 Google LLC
*
* 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
*
* https://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 com.google.samples.apps.iosched.tests
import com.google.samples.apps.iosched.shared.time.DefaultTimeProvider
import com.google.samples.apps.iosched.shared.time.TimeProvider
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import org.threeten.bp.Instant
/**
* Rule to be used in tests that sets the clocked used by DefaultTimeProvider.
*/
class FixedTimeRule(
private val fixedTime: FixedTimeProvider = FixedTimeProvider(1_000_000)
) : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
DefaultTimeProvider.setDelegate(fixedTime)
}
override fun finished(description: Description?) {
super.finished(description)
DefaultTimeProvider.setDelegate(null)
}
}
/**
* Fix the TimeProvider to a fixed time
*/
class FixedTimeProvider(var instant: Instant) : TimeProvider {
constructor(timeInMilis: Long) : this(Instant.ofEpochMilli(timeInMilis))
override fun now(): Instant {
return instant
}
}
@@ -0,0 +1,42 @@
/*
* Copyright 2018 Google LLC
*
* 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
*
* https://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 com.google.samples.apps.iosched.tests
import androidx.test.InstrumentationRegistry
import com.google.samples.apps.iosched.shared.data.prefs.SharedPreferenceStorage
import org.junit.rules.TestWatcher
import org.junit.runner.Description
/**
* Rule to be used in tests that sets the SharedPreferences needed for avoiding onboarding flows,
* resetting filters, etc.
*/
class SetPreferencesRule : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
SharedPreferenceStorage(InstrumentationRegistry.getTargetContext()).apply {
onboardingCompleted = true
scheduleUiHintsShown = true
preferConferenceTimeZone = true
selectedFilters = ""
sendUsageStatistics = false
notificationsPreferenceShown = true
}
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2018 Google LLC
*
* 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
*
* https://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 com.google.samples.apps.iosched.tests
import com.google.samples.apps.iosched.shared.domain.internal.DefaultScheduler
import com.google.samples.apps.iosched.shared.domain.internal.SyncScheduler
import org.junit.rules.TestWatcher
import org.junit.runner.Description
/**
* Rule to be used in tests that sets a synchronous task scheduler used to avoid race conditions.
*/
class SyncTaskExecutorRule : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
DefaultScheduler.setDelegate(SyncScheduler)
}
override fun finished(description: Description?) {
super.finished(description)
DefaultScheduler.setDelegate(null)
}
}
@@ -0,0 +1,78 @@
/*
* Copyright 2018 Google LLC
*
* 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
*
* https://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 com.google.samples.apps.iosched.tests.ui
import androidx.test.InstrumentationRegistry
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import com.google.samples.apps.iosched.R
import com.google.samples.apps.iosched.tests.SetPreferencesRule
import com.google.samples.apps.iosched.tests.SyncTaskExecutorRule
import com.google.samples.apps.iosched.ui.MainActivity
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* Espresso tests for the Info screen, covering main use case.
*/
@RunWith(AndroidJUnit4::class)
class InfoTest {
@get:Rule
var activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
// Executes tasks in a synchronous [TaskScheduler]
@get:Rule
var syncTaskExecutorRule = SyncTaskExecutorRule()
// Sets the preferences so no welcome screens are shown
@get:Rule
var preferencesRule = SetPreferencesRule()
private val resources = InstrumentationRegistry.getTargetContext().resources
@Before
fun goToInfoScreen() {
onView(withId(R.id.navigation_info)).perform(ViewActions.click())
}
@Test
fun info_basicViewsDisplayed() {
onView(withText(resources.getString(R.string.wifi_header))).check(matches(isDisplayed()))
// Travel tab
onView(withText(resources.getString(R.string.travel_title))).perform(click())
onView(withText(resources.getString(R.string.travel_directions_title)))
.check(matches(isDisplayed()))
// About tab
onView(withText(resources.getString(R.string.about_title))).perform(click())
onView(withText(resources.getString(R.string.faq_title))).check(matches(isDisplayed()))
// Setting tab
onView(withText(resources.getString(R.string.settings_title))).perform(click())
onView(withText(resources.getString(R.string.settings_enable_notifications)))
.check(matches(isDisplayed()))
}
}
@@ -0,0 +1,68 @@
/*
* Copyright 2018 Google LLC
*
* 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
*
* https://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 com.google.samples.apps.iosched.tests.ui
import androidx.test.InstrumentationRegistry
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import com.google.samples.apps.iosched.R
import com.google.samples.apps.iosched.tests.SetPreferencesRule
import com.google.samples.apps.iosched.tests.SyncTaskExecutorRule
import com.google.samples.apps.iosched.ui.MainActivity
import org.hamcrest.CoreMatchers.allOf
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* Espresso tests for the Map screen.
*/
@RunWith(AndroidJUnit4::class)
class MapTest {
@get:Rule
var activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
// Executes tasks in a synchronous [TaskScheduler]
@get:Rule
var syncTaskExecutorRule = SyncTaskExecutorRule()
// Sets the preferences so no welcome screens are shown
@get:Rule
var preferencesRule = SetPreferencesRule()
private val resources = InstrumentationRegistry.getTargetContext().resources
@Before
fun goToMapScreen() {
onView(withId(R.id.navigation_map)).perform(ViewActions.click())
}
@Test
fun info_basicViewsDisplayed() {
onView(allOf(withText(resources.getString(R.string.title_map)), withId(R.id.title)))
.check(matches(isDisplayed()))
}
}
Oops, something went wrong.

0 comments on commit beb15c5

Please sign in to comment.