Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
Are there any tools or way to test recomposition happens in a piece of code or not in Jetpack compose?

Are there any tools or way to test recomposition happens in a piece of code or not in Jetpack compose?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There is an example here in the official Compose Testing docs on how you can test if a recomposition takes place, by using composeTestRule.setContent, and in it track the state with a variable visible from the test.

Then you change the state from the test and assert that the tracking variable is equal to the expected state.

@Test
fun counterTest() {
    val myCounter = mutableStateOf(0) // State that can cause recompositions
    var lastSeenValue = 0 // Used to track recompositions
    composeTestRule.setContent {
        Text(myCounter.value.toString())
        lastSeenValue = myCounter.value
    }
    myCounter.value = 1 // The state changes, but there is no recomposition

    // Fails because nothing triggered a recomposition
    assertTrue(lastSeenValue == 1)

    // Passes because the assertion triggers recomposition
    composeTestRule.onNodeWithText("1").assertExists()
}

This example is used to show an edge-case in Compose-Testing for when you don't use methods for UI synchronization in your test (like e.g. onNodeWithText().assertExists()), but I think it could also be usable for your problem.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda