-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
213 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/androidTest/java/com/noumanch/decadeofmovies/ui/activities/MainActivityUITest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.noumanch.decadeofmovies.ui.activities | ||
|
||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import com.noumanch.decadeofmovies.R | ||
|
||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
class MainActivityUITest{ | ||
|
||
@Test | ||
fun test_isActivityInView(){ | ||
val activityScenario = ActivityScenario.launch(MainActivity::class.java) | ||
onView(withId(R.id.main)).check(matches(isDisplayed())) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
app/src/androidTest/java/com/noumanch/decadeofmovies/ui/fragments/MoviesFragmentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.noumanch.decadeofmovies.ui.fragments | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.Espresso.pressBack | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition | ||
import androidx.test.espresso.matcher.ViewMatchers.* | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import com.noumanch.decadeofmovies.R | ||
import com.noumanch.decadeofmovies.ui.activities.MainActivity | ||
import com.noumanch.decadeofmovies.utils.FakeMovieData | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
|
||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
class MoviesFragmentTest { | ||
|
||
@get:Rule | ||
val activityRule = ActivityScenarioRule(MainActivity::class.java) | ||
|
||
val LIST_ITEM_IN_TEST = 9 | ||
val MOVIE_IN_TEST = FakeMovieData.movies[LIST_ITEM_IN_TEST] | ||
|
||
|
||
@Test | ||
fun test_isListFragmentVisible_onAppLaunch() { | ||
onView(withId(R.id.recyclerView)).check(matches(isDisplayed())) | ||
} | ||
|
||
@Test | ||
fun test_selectListItem_isDetailFragmentVisible() { | ||
// Click list item #LIST_ITEM_IN_TEST | ||
onView(withId(R.id.recyclerView)) | ||
.perform(actionOnItemAtPosition<MoviesAdapter.MovieViewHolder>(LIST_ITEM_IN_TEST, click())) | ||
|
||
// Confirm nav to MovieDetailFragment and display title | ||
onView(withId(R.id.movieTitleTV)).check(matches(withText(MOVIE_IN_TEST.title))) | ||
} | ||
|
||
@Test | ||
fun test_backNavigation_toMovieListFragment() { | ||
// Click list item #LIST_ITEM_IN_TEST | ||
onView(withId(R.id.recyclerView)) | ||
.perform(actionOnItemAtPosition<MoviesAdapter.MovieViewHolder>(LIST_ITEM_IN_TEST, click())) | ||
|
||
// Confirm nav to MovieDetailFragment and display title | ||
onView(withId(R.id.movieTitleTV)).check(matches(withText(MOVIE_IN_TEST.title))) | ||
|
||
pressBack() | ||
|
||
// Confirm MoviesFragment in view | ||
onView(withId(R.id.recyclerView)).check(matches(isDisplayed())) | ||
} | ||
} | ||
|
||
|
99 changes: 99 additions & 0 deletions
99
app/src/androidTest/java/com/noumanch/decadeofmovies/utils/FakeMovieData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.noumanch.decadeofmovies.utils | ||
|
||
import com.noumanch.decadeofmovies.models.Movie | ||
|
||
object FakeMovieData { | ||
|
||
val movies = arrayOf( | ||
Movie( | ||
0, | ||
"Avengers: Infinity War", | ||
2012,2, | ||
arrayListOf("Anthony Russo", "Joe Russo"), | ||
arrayListOf("Robert Downey Jr.", "Chris Hemsworth", "Mark Ruffalo", "+ more...") | ||
), | ||
Movie( | ||
1, | ||
"The Rundown", | ||
2012,2, | ||
arrayListOf("R.J. Stewart", "James Vanderbilt"), | ||
arrayListOf("Dwayne Johnson", "Seann William Scott", "Rosario Dawson", "Christopher Walken") | ||
), | ||
Movie( | ||
2, | ||
"The Godfather", | ||
2012,2, | ||
arrayListOf("Francis Ford Coppola"), | ||
arrayListOf("Marlon Brando", "Al Pacino", "James Caan") | ||
), | ||
Movie( | ||
3, | ||
"The Dark Knight", | ||
2012,2, | ||
arrayListOf("Christopher Nolan"), | ||
arrayListOf("Christian Bale", "Heath Ledger", "Aaron Eckhart") | ||
), | ||
Movie( | ||
4, | ||
"The Lord of the Rings: The Return of the King", | ||
2012,2, | ||
arrayListOf("Peter Jackson"), | ||
arrayListOf("Elijah Wood", "Viggo Mortensen", "Ian McKellen") | ||
), | ||
Movie( | ||
3, | ||
"The Dark Knight", | ||
2012,2, | ||
arrayListOf("Christopher Nolan"), | ||
arrayListOf("Christian Bale", "Heath Ledger", "Aaron Eckhart") | ||
), | ||
Movie( | ||
4, | ||
"The Lord of the Rings: The Return of the King", | ||
2012,2, | ||
arrayListOf("Peter Jackson"), | ||
arrayListOf("Elijah Wood", "Viggo Mortensen", "Ian McKellen") | ||
), | ||
Movie( | ||
5, | ||
"The Dark Knight", | ||
2012,2, | ||
arrayListOf("Christopher Nolan"), | ||
arrayListOf("Christian Bale", "Heath Ledger", "Aaron Eckhart") | ||
), | ||
Movie( | ||
6, | ||
"The Lord of the Rings: The Return of the King", | ||
2012,2, | ||
arrayListOf("Peter Jackson"), | ||
arrayListOf("Elijah Wood", "Viggo Mortensen", "Ian McKellen") | ||
), | ||
Movie( | ||
7, | ||
"The Dark Knight", | ||
2012,2, | ||
arrayListOf("Christopher Nolan"), | ||
arrayListOf("Christian Bale", "Heath Ledger", "Aaron Eckhart") | ||
), | ||
Movie( | ||
8, | ||
"The Lord of the Rings: The Return of the King", | ||
2012,2, | ||
arrayListOf("Peter Jackson"), | ||
arrayListOf("Elijah Wood", "Viggo Mortensen", "Ian McKellen") | ||
), Movie( | ||
9, | ||
"The Dark Knight", | ||
2012,2, | ||
arrayListOf("Christopher Nolan"), | ||
arrayListOf("Christian Bale", "Heath Ledger", "Aaron Eckhart") | ||
), | ||
Movie( | ||
10, | ||
"The Lord of the Rings: The Return of the King", | ||
2012,2, | ||
arrayListOf("Peter Jackson"), | ||
arrayListOf("Elijah Wood", "Viggo Mortensen", "Ian McKellen") | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/noumanch/decadeofmovies/utils/EspressoIdlingResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.noumanch.decadeofmovies.utils | ||
|
||
import androidx.test.espresso.idling.CountingIdlingResource | ||
|
||
object EspressoIdlingResource { | ||
|
||
private const val RESOURCE = "GLOBAL" | ||
|
||
@JvmField val countingIdlingResource = CountingIdlingResource(RESOURCE) | ||
|
||
fun increment() { | ||
countingIdlingResource.increment() | ||
} | ||
|
||
fun decrement() { | ||
if (!countingIdlingResource.isIdleNow) { | ||
countingIdlingResource.decrement() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters