[FR]: Enhance flow testing methodology using backgroundScope

Abierto
#1,591 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
20/100
Tipo de issue
Refactorización
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
android, kotlin
Área
mobile, testing

Línea de trabajo

Comienza revisando el patrón existente de recopilación de flow en la prueba de ViewModel y compáralo con la documentación para desarrolladores de Android sobre backgroundScope. Identifica las otras pruebas relevantes de flow que crean y cancelan jobs manualmente, y luego ejecuta la suite de pruebas para confirmar que la metodología actualizada funciona sin cancelación manual.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement
Is there an existing issue for this?
  • I have searched the existing issues
Describe the problem

Currently, our flow testing methodology in the NowInAndroid project requires manually creating and canceling job objects to collect flows during tests. This approach can be error-prone and doesn't align with the latest best practices recommended in the Android developer documentation. (example in viewModel test )

Describe the solution

I propose updating our flow testing methodology to utilize backgroundScope for collecting flows. This solution offers several benefits:

  1. Eliminates the need to manually create and cancel job objects.
  2. Provides automatic cancellation of the coroutine before the end of the test.
  3. Aligns with the latest best practices as documented by Android developers.

Implementation details:

• Replace current job creation and cancellation with backgroundScope.
• Update relevant test cases to use this new methodology.
• Ensure all tests pass with the new implementation.

References:

  1. https://developer.android.com/kotlin/flow/test

  2. https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/background-scope.html

i have already created a pull request implementing this change: https://github.com/android/nowinandroid/pull/1585

Additional context

This change will simplify our test code, reduce the risk of forgetting to cancel job objects, and improve our alignment with current Android development best practices. It will make our tests more robust and easier to maintain in the long run.

Code of Conduct
  • I agree to follow this project's Code of Conduct
Lenguaje dominante
Kotlin
Estrellas
22.1k
Forks
4.7k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de android/nowinandroid

Todos los issues de android/nowinandroid

Issues similares

Más issues de Kotlin

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.