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

[Compose] Optimize to test "SharedFlow" execution in Composable with Robolectric #465

Closed
luongvo opened this issue May 17, 2023 · 2 comments · Fixed by #466
Closed

[Compose] Optimize to test "SharedFlow" execution in Composable with Robolectric #465

luongvo opened this issue May 17, 2023 · 2 comments · Fixed by #466

Comments

@luongvo
Copy link
Member

luongvo commented May 17, 2023

Why

According to the last implementation of running the Jetpack Compose UI Test with Robolectric, we have to switch the error from SharedFlow to StateFlow because we can not make it to be testable with Robolectric.

Using LaunchedEffect in Jetpack Compose is a standard best practice, and it's hard to find a replacement for LaunchedEffect. So in the big picture, if we can not test SharedFlow execution by LaunchedEffect in Composable with Robolectric, we cannot use Robolectric as our main testing framework for Jetpack Compose to cover all project business logic.

Hence, we should research & find a valid way to test SharedFlow execution in Composable with Robolectric without converting it to StateFlow. This also helps to apply using viewModel.error.collectAsEffect for error handling instead of

val error: Throwable? by viewModel.error.collectAsStateWithLifecycle()
error?.showToast(context)

Who Benefits?

Developers

@ryan-conway
Copy link
Collaborator

@luongvo This issue seems very opened ended, I can't see how to define clear acceptance criteria here 🤔 Do you have a concrete suggestion for how to resolve this issue?

@luongvo
Copy link
Member Author

luongvo commented May 18, 2023

@luongvo This issue seems very opened ended, I can't see how to define clear acceptance criteria here 🤔 Do you have a concrete suggestion for how to resolve this issue?

@ryan-conway It's still an experiment. However, I found a way to resolve it, so clarifying it in the PR is better 🙏

luongvo added a commit that referenced this issue May 19, 2023
@ryan-conway ryan-conway added this to the 3.20.0 milestone May 19, 2023
ryan-conway added a commit that referenced this issue May 25, 2023
…ecution-in-composable-with-robolectric

[#465] [Compose] Optimize to test "SharedFlow" execution in Composable with Robolectric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment