[FR]: Enhance flow testing methodology using backgroundScope

Aperta
#1,591 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
20/100
Tipo di issue
Refactoring
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
android, kotlin
Ambito
mobile, testing

Direzione di ricerca

Inizia esaminando il pattern esistente di raccolta di flow nel test di ViewModel e confrontalo con la documentazione per sviluppatori Android relativa a backgroundScope. Identifica gli altri test rilevanti di flow che creano e annullano manualmente i jobs, quindi esegui la suite di test per confermare che la metodologia aggiornata funzioni senza annullamento manuale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Kotlin
Stelle
22.1k
Fork
4.7k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di android/nowinandroid

Tutte le issue di android/nowinandroid

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.