[FR]: Enhance flow testing methodology using backgroundScope

オープン
#1,591 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
20/100
issue の種類
リファクタリング
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
android, kotlin
領域
mobile, testing

調査の方向性

まず、ViewModel のテストにおける既存の flow 収集パターンを確認し、Android 開発者向けドキュメントの backgroundScope に関する説明と比較します。手動で jobs を作成してキャンセルしている、その他の関連する flow テストを特定し、その後テストスイートを実行して、更新された方法が手動キャンセルなしで通過することを確認します。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Kotlin
スター
22.1k
フォーク
4.7k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

android/nowinandroid のほかの issue

android/nowinandroid の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。