Skip to content

Commit

Permalink
Merge pull request #187 from xizzhu/e2e-testing
Browse files Browse the repository at this point in the history
Added end-to-end testing
  • Loading branch information
xizzhu authored Jun 5, 2020
2 parents cb1e954 + 2dc5710 commit 5b19ba4
Show file tree
Hide file tree
Showing 63 changed files with 2,159 additions and 42 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ branches:
before_script:
- android list targets
- echo no | android create avd --force -n test -t android-25 --abi google_apis/arm64-v8a
- emulator -avd test -no-skin -no-window &
- emulator -avd test -no-window &
- android-wait-for-emulator
- adb shell settings put global window_animation_scale 0 &
- adb shell settings put global transition_animation_scale 0 &
- adb shell settings put global animator_duration_scale 0 &
- adb shell input keyevent 82 &

script:
- ./gradlew -Pcoverage clean coveralls
- ./gradlew -Pcoverage -PdisablePreDex clean coveralls

notifications:
email: false
6 changes: 2 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ android {
}
}

tasks.withType(Test::class.java) {
maxParallelForks = Runtime.getRuntime().availableProcessors() / 2
}

dependencies {
implementation(Dependencies.Kotlin.stdlib)
implementation(Dependencies.Kotlin.coroutinesAndroid)
Expand Down Expand Up @@ -150,6 +146,8 @@ dependencies {
androidTestImplementation(Dependencies.Kotlin.coroutinesTest)
androidTestImplementation(Dependencies.AndroidX.Test.junit)
androidTestImplementation(Dependencies.AndroidX.Test.rules)
androidTestImplementation(Dependencies.AndroidX.Test.Espresso.core)
androidTestImplementation(Dependencies.AndroidX.Test.Espresso.contrib)
androidTestImplementation(Dependencies.Mockito.mockito)
androidTestImplementation(Dependencies.Mockito.android)
}
Expand Down
133 changes: 133 additions & 0 deletions app/src/androidTest/kotlin/me/xizzhu/android/joshua/Injection.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright (C) 2020 Xizhi Zhu
*
* 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 me.xizzhu.android.joshua

import dagger.Module
import dagger.Provides
import me.xizzhu.android.joshua.core.*
import me.xizzhu.android.joshua.core.repository.*
import me.xizzhu.android.joshua.core.repository.local.android.*
import me.xizzhu.android.joshua.core.repository.local.android.db.AndroidDatabase
import me.xizzhu.android.joshua.core.repository.remote.android.HttpStrongNumberService
import me.xizzhu.android.joshua.core.repository.remote.android.HttpTranslationService
import javax.inject.Scope
import javax.inject.Singleton

@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ActivityScope

@Module
class AppModule(private val app: App) {
@Provides
@Singleton
fun provideApp(): App = app

companion object {
@Provides
@Singleton
fun provideNavigator(): Navigator = Navigator()

@Provides
@Singleton
fun provideBackupManager(bookmarkRepository: VerseAnnotationRepository<Bookmark>,
highlightRepository: VerseAnnotationRepository<Highlight>,
noteRepository: VerseAnnotationRepository<Note>,
readingProgressRepository: ReadingProgressRepository): BackupManager = BackupManager

@Provides
@Singleton
fun provideBibleReadingManager(bibleReadingRepository: BibleReadingRepository,
translationRepository: TranslationRepository): BibleReadingManager = BibleReadingManager

@Provides
@Singleton
fun provideBookmarkManager(bookmarkRepository: VerseAnnotationRepository<Bookmark>): VerseAnnotationManager<Bookmark> =
VerseAnnotationManager(bookmarkRepository)

@Provides
@Singleton
fun provideHighlightManager(highlightRepository: VerseAnnotationRepository<Highlight>): VerseAnnotationManager<Highlight> =
VerseAnnotationManager(highlightRepository)

@Provides
@Singleton
fun provideNoteManager(noteRepository: VerseAnnotationRepository<Note>): VerseAnnotationManager<Note> =
VerseAnnotationManager(noteRepository)

@Provides
@Singleton
fun provideReadingProgressManager(bibleReadingRepository: BibleReadingRepository,
readingProgressRepository: ReadingProgressRepository): ReadingProgressManager = ReadingProgressManager

@Provides
@Singleton
fun provideSettingsManager(settingsRepository: SettingsRepository): SettingsManager = SettingsManager

@Provides
@Singleton
fun provideStrongNumberManager(strongNumberRepository: StrongNumberRepository): StrongNumberManager = StrongNumberManager

@Provides
@Singleton
fun provideTranslationManager(translationRepository: TranslationRepository): TranslationManager = TranslationManager
}
}

@Module
object RepositoryModule {
@Provides
@Singleton
fun provideAndroidDatabase(app: App): AndroidDatabase = AndroidDatabase(app)

@Provides
@Singleton
fun provideBibleReadingRepository(androidDatabase: AndroidDatabase): BibleReadingRepository =
BibleReadingRepository(AndroidReadingStorage(androidDatabase))

@Provides
@Singleton
fun provideBookmarkRepository(androidDatabase: AndroidDatabase): VerseAnnotationRepository<Bookmark> = BookmarksRepository

@Provides
@Singleton
fun provideHighlightRepository(androidDatabase: AndroidDatabase): VerseAnnotationRepository<Highlight> = HighlightsRepository

@Provides
@Singleton
fun provideNoteRepository(androidDatabase: AndroidDatabase): VerseAnnotationRepository<Note> = NotesRepository

@Provides
@Singleton
fun provideReadingProgressRepository(androidDatabase: AndroidDatabase): ReadingProgressRepository =
ReadingProgressRepository(AndroidReadingProgressStorage(androidDatabase))

@Provides
@Singleton
fun provideSettingsRepository(androidDatabase: AndroidDatabase): SettingsRepository =
SettingsRepository(AndroidSettingsStorage(androidDatabase))

@Provides
@Singleton
fun provideStrongNumberRepository(androidDatabase: AndroidDatabase): StrongNumberRepository =
StrongNumberRepository(AndroidStrongNumberStorage(androidDatabase), HttpStrongNumberService())

@Provides
@Singleton
fun provideTranslationRepository(androidDatabase: AndroidDatabase): TranslationRepository =
TranslationRepository(AndroidTranslationStorage(androidDatabase), HttpTranslationService())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2020 Xizhi Zhu
*
* 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 me.xizzhu.android.joshua.annotated.bookmarks

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import me.xizzhu.android.joshua.annotated.bookmarks.list.BookmarkItem
import me.xizzhu.android.joshua.core.BibleReadingManager
import me.xizzhu.android.joshua.core.Bookmark
import me.xizzhu.android.joshua.core.Constants
import me.xizzhu.android.joshua.core.VerseIndex
import me.xizzhu.android.joshua.core.repository.BookmarksRepository
import me.xizzhu.android.joshua.tests.EspressoTestRule
import me.xizzhu.android.joshua.tests.MockContents
import me.xizzhu.android.joshua.tests.robots.BookmarksActivityRobot
import org.junit.Rule
import org.junit.runner.RunWith
import kotlin.test.Test
import kotlin.test.assertEquals

@RunWith(AndroidJUnit4::class)
@LargeTest
class BookmarksActivityTest {
@get:Rule
val activityRule = EspressoTestRule(BookmarksActivity::class.java)

@Test
fun testEmptyBookmarks() {
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName)
val robot = BookmarksActivityRobot(activityRule.activity)
.isNoBookmarksDisplayed()

BookmarksRepository.sortOrder.offer(Constants.SORT_BY_BOOK)
robot.isNoBookmarksDisplayed()
}

@Test
fun testBookmarks() {
val now = System.currentTimeMillis()
val bookmarks = listOf(
Bookmark(VerseIndex(0, 0, 4), now),
Bookmark(VerseIndex(0, 0, 0), now)
)
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName)
BookmarksRepository.annotations = bookmarks
BookmarksActivityRobot(activityRule.activity)
.areBookmarksDisplayed(bookmarks.map { bookmark ->
BookmarkItem(
bookmark.verseIndex,
MockContents.kjvBookNames[bookmark.verseIndex.bookIndex],
MockContents.kjvBookShortNames[bookmark.verseIndex.bookIndex],
MockContents.kjvVerses[bookmark.verseIndex.verseIndex].text.text,
Constants.DEFAULT_SORT_ORDER,
{}
)
})
.clickBookmark(0)

assertEquals(VerseIndex(0, 0, 4), BibleReadingManager.currentVerseIndex.value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2020 Xizhi Zhu
*
* 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 me.xizzhu.android.joshua.annotated.highlights

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import me.xizzhu.android.joshua.annotated.highlights.list.HighlightItem
import me.xizzhu.android.joshua.core.*
import me.xizzhu.android.joshua.core.repository.HighlightsRepository
import me.xizzhu.android.joshua.tests.EspressoTestRule
import me.xizzhu.android.joshua.tests.MockContents
import me.xizzhu.android.joshua.tests.robots.HighlightsActivityRobot
import org.junit.Rule
import org.junit.runner.RunWith
import kotlin.test.Test
import kotlin.test.assertEquals

@RunWith(AndroidJUnit4::class)
@LargeTest
class HighlightsActivityTest {
@get:Rule
val activityRule = EspressoTestRule(HighlightsActivity::class.java)

@Test
fun testEmptyHighlights() {
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName)
val robot = HighlightsActivityRobot(activityRule.activity)
.isNoHighlightsDisplayed()

HighlightsRepository.sortOrder.offer(Constants.SORT_BY_BOOK)
robot.isNoHighlightsDisplayed()
}

@Test
fun testHighlights() {
val now = System.currentTimeMillis()
val highlights = listOf(
Highlight(VerseIndex(0, 0, 4), Highlight.COLOR_BLUE, now),
Highlight(VerseIndex(0, 0, 0), Highlight.COLOR_PINK, now)
)
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName)
HighlightsRepository.annotations = highlights
HighlightsActivityRobot(activityRule.activity)
.areHighlightsDisplayed(highlights.map { highlight ->
HighlightItem(
highlight.verseIndex,
MockContents.kjvBookNames[highlight.verseIndex.bookIndex],
MockContents.kjvBookShortNames[highlight.verseIndex.bookIndex],
MockContents.kjvVerses[highlight.verseIndex.verseIndex].text.text,
highlight.color,
Constants.DEFAULT_SORT_ORDER,
{}
)
})
.clickHighlight(0)

assertEquals(VerseIndex(0, 0, 4), BibleReadingManager.currentVerseIndex.value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2020 Xizhi Zhu
*
* 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 me.xizzhu.android.joshua.annotated.notes

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import me.xizzhu.android.joshua.annotated.notes.list.NoteItem
import me.xizzhu.android.joshua.core.*
import me.xizzhu.android.joshua.core.repository.NotesRepository
import me.xizzhu.android.joshua.tests.EspressoTestRule
import me.xizzhu.android.joshua.tests.MockContents
import me.xizzhu.android.joshua.tests.robots.NotesActivityRobot
import org.junit.Rule
import org.junit.runner.RunWith
import kotlin.test.Test
import kotlin.test.assertEquals

@RunWith(AndroidJUnit4::class)
@LargeTest
class NotesActivityTest {
@get:Rule
val activityRule = EspressoTestRule(NotesActivity::class.java)

@Test
fun testEmptyNotes() {
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName)
val robot = NotesActivityRobot(activityRule.activity)
.isNoNotesDisplayed()

NotesRepository.sortOrder.offer(Constants.SORT_BY_BOOK)
robot.isNoNotesDisplayed()
}

@Test
fun testNotes() {
val now = System.currentTimeMillis()
val notes = listOf(
Note(VerseIndex(0, 0, 4), "some random note", now),
Note(VerseIndex(0, 0, 0), "more sample", now)
)
BibleReadingManager.currentTranslation.offer(MockContents.kjvShortName)
NotesRepository.annotations = notes
NotesActivityRobot(activityRule.activity)
.areNotesDisplayed(notes.map { note ->
NoteItem(
note.verseIndex,
MockContents.kjvBookShortNames[note.verseIndex.bookIndex],
MockContents.kjvVerses[note.verseIndex.verseIndex].text.text,
note.note,
{}
)
})
.clickNote(0)

assertEquals(VerseIndex(0, 0, 4), BibleReadingManager.currentVerseIndex.value)
}
}
Loading

0 comments on commit 5b19ba4

Please sign in to comment.