Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR]: Enhance flow testing methodology using backgroundScope #1591

Open
2 tasks done
saeedishayan76 opened this issue Sep 4, 2024 · 0 comments
Open
2 tasks done

[FR]: Enhance flow testing methodology using backgroundScope #1591

saeedishayan76 opened this issue Sep 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@saeedishayan76
Copy link
Contributor

saeedishayan76 commented Sep 4, 2024

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: #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
@saeedishayan76 saeedishayan76 added the enhancement New feature or request label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant