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

End to End tests fail in the more recent compose versions #5

Open
NunoPontes opened this issue Jun 12, 2022 · 2 comments
Open

End to End tests fail in the more recent compose versions #5

NunoPontes opened this issue Jun 12, 2022 · 2 comments

Comments

@NunoPontes
Copy link

NunoPontes commented Jun 12, 2022

Hello Philipp,

I've really enjoyed this course, congrats.

I've been upgrading the dependencies on this project to test something, and when I upgrade:

Gradle to 7.2.1
Kotlin to 1.6.21
Compose to 1.2.0-beta03

When running the TrackerOverviewE2E tests I get the following error:

com.plcoding.calorytracker.MainActivity@24abf32 has already set content. If you have populated the Activity with a ComposeView, make sure to call setContent on that ComposeView instead of on the test rule; and make sure that that call to setContent {} is done after the ComposeTestRule has run at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$AndroidComposeUiTestImpl.setContent(ComposeUiTest.android.kt:470) at androidx.compose.ui.test.junit4.AndroidComposeTestRule.setContent(AndroidComposeTestRule.android.kt:200) at com.plcoding.calorytracker.TrackerOverviewE2E.setUp(TrackerOverviewE2E.kt:101)

@cbarrios
Copy link

cbarrios commented Oct 11, 2022

Hi @NunoPontes,

This is how it can be fixed. Please follow the following steps:

  1. Change the composeRule to the following type. Please replace ... inside <...> by ComponentActivity
    @get:Rule
    val composeRule = createAndroidComposeRule<...>()

  2. Add the following dependency to your app module build.gradle.kts:
    debugImplementation("androidx.compose.ui:ui-test-manifest:1.3.0-rc01")

Enjoy.

@Arturo785
Copy link

Arturo785 commented Apr 5, 2023

Actually that approach didn't work but this did the trick
https://stackoverflow.com/questions/73191692/test-errormyactivity-has-already-set-content-if-you-have-populated-the-activit

basically composeRule.activity.setContent { }
instead of composeRule.setContent { }`

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

No branches or pull requests

3 participants