Add test repetition
This commit is contained in:
parent
dce522bc46
commit
f3f3fb97f8
|
@ -103,7 +103,7 @@ dependencies {
|
|||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
|
||||
implementation 'androidx.paging:paging-runtime-ktx:3.0.0-beta03'
|
||||
implementation 'androidx.paging:paging-runtime-ktx:3.0.0-rc01'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1'
|
||||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
|
||||
|
|
|
@ -19,9 +19,11 @@ import org.junit.After
|
|||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.rules.Timeout
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.runners.model.Statement
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class HomeFeedTest {
|
||||
|
@ -30,6 +32,9 @@ class HomeFeedTest {
|
|||
private lateinit var db: AppDatabase
|
||||
private lateinit var context: Context
|
||||
|
||||
@Rule @JvmField
|
||||
var repeatRule: RepeatRule = RepeatRule()
|
||||
|
||||
@get:Rule
|
||||
var globalTimeout: Timeout = Timeout.seconds(100)
|
||||
|
||||
|
@ -53,6 +58,7 @@ class HomeFeedTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@RepeatTest
|
||||
fun clickingTabOnAlbumShowsNextPhoto() {
|
||||
//Wait for the feed to load
|
||||
waitForView(R.id.postPager)
|
||||
|
@ -126,6 +132,7 @@ class HomeFeedTest {
|
|||
}*/
|
||||
|
||||
@Test
|
||||
@RepeatTest
|
||||
fun clickingUsernameOpensProfile() {
|
||||
waitForView(R.id.username)
|
||||
|
||||
|
@ -136,6 +143,7 @@ class HomeFeedTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@RepeatTest
|
||||
fun clickingProfilePicOpensProfile() {
|
||||
waitForView(R.id.profilePic)
|
||||
|
||||
|
@ -146,6 +154,7 @@ class HomeFeedTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@RepeatTest
|
||||
fun clickingMentionOpensProfile() {
|
||||
waitForView(R.id.description)
|
||||
|
||||
|
@ -216,6 +225,7 @@ class HomeFeedTest {
|
|||
.check(matches(hasDescendant(withId(R.id.comment))))
|
||||
}*/
|
||||
|
||||
@RepeatTest
|
||||
@Test
|
||||
fun performClickOnSensitiveWarning() {
|
||||
waitForView(R.id.username)
|
||||
|
@ -231,6 +241,7 @@ class HomeFeedTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@RepeatTest
|
||||
fun performClickOnSensitiveWarningTabs() {
|
||||
waitForView(R.id.username)
|
||||
|
||||
|
|
|
@ -21,9 +21,37 @@ import org.hamcrest.CoreMatchers.allOf
|
|||
import org.hamcrest.Description
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.Matchers
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runners.model.Statement
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS)
|
||||
annotation class RepeatTest(val value: Int = 1)
|
||||
|
||||
class RepeatRule : TestRule {
|
||||
|
||||
private class RepeatStatement(private val statement: Statement, private val repeat: Int) : Statement() {
|
||||
@Throws(Throwable::class)
|
||||
override fun evaluate() {
|
||||
for (i in 0 until repeat) {
|
||||
statement.evaluate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun apply(statement: Statement, description: org.junit.runner.Description): Statement {
|
||||
var result = statement
|
||||
val repeat = description.getAnnotation(RepeatTest::class.java)
|
||||
if (repeat != null) {
|
||||
val times = repeat.value
|
||||
result = RepeatStatement(statement, times)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun ViewInteraction.isDisplayed(): Boolean {
|
||||
return try {
|
||||
check(matches(ViewMatchers.isDisplayed()))
|
||||
|
|
|
@ -70,12 +70,8 @@ class PostFeedFragment<T: FeedContentDatabase>: CachedFeedFragment<T>() {
|
|||
|
||||
inner class PostsAdapter(private val displayDimensionsInPx: Pair<Int, Int>) : PagingDataAdapter<T, RecyclerView.ViewHolder>(
|
||||
object : DiffUtil.ItemCallback<T>() {
|
||||
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean =
|
||||
oldItem.id == newItem.id
|
||||
override fun areItemsTheSame (oldItem: T, newItem: T): Boolean = oldItem.id == newItem.id
|
||||
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean = oldItem.id == newItem.id
|
||||
}
|
||||
) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue