Skip to content
New issue

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

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

Already on GitHub? # to your account

Implement LifecycleOwner in tests #1294

Open
wants to merge 1 commit into
base: jb-main
Choose a base branch
from
Open

Conversation

kropp
Copy link
Member

@kropp kropp commented Apr 19, 2024

Proposed Changes

  • Implement LifecycleOwner in tests, provide it in LocalLifecycleOwner
  • Provide the means to change Lifecycle in runComposeUiTest

Testing

Test: LifecycleInTestsTest

Comment on lines +151 to +152
implementation(project(":lifecycle:lifecycle-common"))
implementation(project(":lifecycle:lifecycle-runtime"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be in common?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't used in Android or commonMain, so we should keep it here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not required in common, as I introduced changes in skikoMain/skikoTest only, so I decided to include dependencies only for these source roots.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see some common API at some point, but it requires changes in AOSP first

lifecycleOwner.lifecycle.handleLifecycleEvent(event)
}

private fun ProvideTestCompositionLocals(composable: @Composable () -> Unit): @Composable () -> Unit = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private fun ProvideTestCompositionLocals(composable: @Composable () -> Unit): @Composable () -> Unit = {
@Composable
private fun ProvideTestCompositionLocals(content: @Composable () -> Unit) {

@@ -443,4 +462,9 @@ actual sealed interface ComposeUiTest : SemanticsNodeInteractionsProvider {
actual fun registerIdlingResource(idlingResource: IdlingResource)
actual fun unregisterIdlingResource(idlingResource: IdlingResource)
actual fun setContent(composable: @Composable () -> Unit)
fun sendLifecycleEvent(event: Lifecycle.Event)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KDoc is required for all public APIs

@m-sasha
Copy link
Member

m-sasha commented Apr 19, 2024

Does Android provide LifecycleOwner in tests?

@igordmn igordmn removed their request for review April 19, 2024 15:55
@igordmn
Copy link
Collaborator

igordmn commented Apr 19, 2024

Does Android provide LifecycleOwner in tests?

I don't think so.

Delegating the review to m-sasha, as the owner of ui-test

@MatkovIvan
Copy link
Member

MatkovIvan commented Apr 19, 2024

@m-sasha LocalLifecycleOwner should be available, yes.
For sending events: rule.scenario.moveToState(RESUMED)

@m-sasha
Copy link
Member

m-sasha commented Apr 19, 2024

If Android's ui-test doesn't include lifecycle stuff, I'm thinking maybe we shouldn't either. Can we provide the same functionality from e.g. lifecycle-test?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants