Android Instrumentation Testing

Android Instrumentation Testing

See more

--

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.")

}

Relates to

References