Android Instrumentation Testing
Android Instrumentation Testing
- Create a
androidTest/java
folder inside yoursrc
directory - Create a package by right-clicking and selecting
New -> Package
- Create a Kotlin file
--
import androidx.compose.ui.test.junit4.createComposeRule
import org.junit.Rule
class TipUITests {
// Declared compose instance
@get:Rule
val composeTestRule = createComposeRule()
// Declare test
@Test
fun calculate_20_percent_tip() {
composeTestRule.setContent {
TipTimeTheme {
TipTimeScreen()
}
}
}
// Performe actions
composeTestRule.onNodeWithText("Bill Amount")
.performTextInput("10")
// Performe actions
composeTestRule.onNodeWithText("Tip (%)")
.performTextInput("20")
val expectedTip = NumberFormat.getCurrencyInstance().format(2)
composeTestRule.onNodeWithText("Tip Amount: $expectedTip")
//Assertion
.assertExists("No node with this text was found.")
}