Skip to content

Comments

Implement LifecycleOwner in tests#1294

Closed
kropp wants to merge 1 commit intojb-mainfrom
kropp/lifecycle-in-tests
Closed

Implement LifecycleOwner in tests#1294
kropp wants to merge 1 commit intojb-mainfrom
kropp/lifecycle-in-tests

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

@kropp kropp requested review from MatkovIvan and igordmn April 19, 2024 14:32
@MatkovIvan MatkovIvan requested a review from m-sasha April 19, 2024 14:34
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

@kropp kropp force-pushed the kropp/lifecycle-in-tests branch from b7acd5b to c42d96d Compare April 19, 2024 15:39
@kropp kropp requested review from MatkovIvan and igordmn April 19, 2024 15:39
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) {

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

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

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?

@nenros
Copy link

nenros commented Feb 11, 2025

hi! Are any plans to merge that pull request? and changes needed?

@MatkovIvan
Copy link
Member

#2400

@MatkovIvan MatkovIvan closed this Sep 15, 2025
MatkovIvan added a commit that referenced this pull request Sep 16, 2025
…2400)

Fixes [CMP-7419](https://youtrack.jetbrains.com/issue/CMP-7419)
CompositionLocal LocalLifecycleOwner not present on
iosSimulatorArm64Test task

Replacemed of #1294 with no public API for now. The target here is
provide unified default behavior between platforms and unblock
navigation tests in `commonTest` without additional workarounds.

## Release Notes
### Features - Multiple Platforms
- Provide `LocalLifecycleOwner` inside `runComposeUiTest` by default

---------

Co-authored-by: Victor Kropp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants