Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Espresso test to GameListActivity #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.1"
// Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'androidx.test.espresso:espresso-contrib:3.5.1'
kapt 'com.github.bumptech.glide:compiler:4.12.0'
kapt "com.android.databinding:compiler:3.1.4"

Expand All @@ -66,4 +67,8 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.joaovictorsl.adafreetoplaygames

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import me.joaovictorsl.adafreetoplaygames.ui.gamelist.GameListActivity
import me.joaovictorsl.adafreetoplaygames.ui.recyclerview.adapter.GameAdapter
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class GameListActivityTest {
@get:Rule
val activityScenarioRule = ActivityScenarioRule(GameListActivity::class.java)

@Test
fun testScrollAndClickRecyclerViewItem() {
// Espera API
Thread.sleep(3000)

// Realiza a rolagem até a posição desejada
onView(withId(R.id.game_list_recycler_view))
.perform(RecyclerViewActions.scrollToPosition<GameAdapter.GameViewHolder>(10))

Thread.sleep(3000)

// Clica no item na posição desejada
onView(withId(R.id.game_list_recycler_view))
.perform(
RecyclerViewActions.actionOnItemAtPosition<GameAdapter.GameViewHolder>(
10,
click(),
),
)

Thread.sleep(3000)
}
}