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

change collectJob to backgroundScope coroutine #1585

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

saeedishayan76
Copy link

Hello,
‌Based on the latest document available in developer.android, we can use backgroundScope to collect flows instead of making a job object and canceling it after the final assertion.
With that, we do not need to manually cancel the created job, and the cancellation of this coroutine is done automatically before the end of the test. The following links are about the example on the site of developer.android and kotllinlang:

https://developer.android.com/kotlin/flow/test
Screenshot 2024-09-02 at 8 04 01 PM

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

@Jaehwa-Noh
Copy link
Contributor

I'd also tried that approach before, but I've got fail on unit tests.
Did you pass the unit tests on this PR?

@saeedishayan76
Copy link
Author

I'd also tried that approach before, but I've got fail on unit tests. Did you pass the unit tests on this PR?

yes , i check unit test (in feature) after change in android studio and all test passed.

@alexvanyo alexvanyo self-requested a review September 13, 2024 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants