Please conduct the following tasks alone. For implementation details you can refer to the lecture slides or the Android developer website. Please do not hesitate to ask me or the tutor if you have any questions.
Search Screen:
Home Screen:
Hint: The test is expecting a empty app state. If you have saved movies on app start, the test will fail.
package de.hdmstuttgart.movietracker
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import org.junit.Rule
import org.junit.Test
class Assignment5Test {
@get:Rule
var composeTestRule = createAndroidComposeRule<MainActivity>()
@Test
fun test1() {
composeTestRule.onNodeWithTag("openSearchButton").performClick()
composeTestRule.onNodeWithTag("textField").performTextInput("Matrix")
composeTestRule.onNodeWithTag("searchButton").performClick()
Thread.sleep(1000)
composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
composeTestRule.onAllNodesWithTag("movieItem")[0].performClick()
composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
}
@Test
fun test2() {
composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
composeTestRule.onNodeWithTag("openSearchButton").performClick()
composeTestRule.onNodeWithTag("textField").performTextInput("her")
composeTestRule.onNodeWithTag("searchButton").performClick()
Thread.sleep(1000)
composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("Her")
composeTestRule.onAllNodesWithTag("movieItem")[0].performClick()
}
@Test
fun test3() {
composeTestRule.onAllNodesWithTag("movieItem")[0].assertTextContains("The Matrix")
composeTestRule.onAllNodesWithTag("movieItem")[1].assertTextContains("Her")
}
}
Module build.gradle.kts
:
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.room.gradle.plugin)
implementation(libs.androidx.room.runtime)
annotationProcessor(libs.androidx.room.compiler)
ksp(libs.androidx.room.compiler)
implementation(libs.androidx.room.ktx)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
implementation(libs.coil.compose)
ksp(libs.compiler)
implementation(libs.converter.gson)
implementation(libs.retrofit)
}