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

IllegalStateException: Given component holder class ComposableTestActivity does not implement interface GeneratedComponent #207

Open
1 of 6 tasks
djette-st opened this issue Feb 26, 2024 · 2 comments
Labels
Bug Any behaviour the deviates from the documentation, expected outcome or API contract. Extension Relates to one of the extension libraries

Comments

@djette-st
Copy link
Contributor

Describe the bug

When using HiltAndroidRule from Dagger/Hilt 2.49+ with Testify, an IllegalStateException is thrown.

@HiltAndroidTest
class NavigationTest {

    @get:Rule(order = 0)
    var hiltRule = HiltAndroidRule(this)

    @get:Rule(order = 1)
    val rule = ComposableScreenshotRule(composeTestRule = createAndroidComposeRule(ComposableTestActivity::class.java))

    @ScreenshotInstrumentation
    @Test
    fun default() {
      rule
          .setComposeActions { composeTestRule ->
              composeTestRule.setContent {
                MainNavigation()
              }
          }
          .assertSame()
    }
}

This issue relates to:

  • Compose Extension
  • The Kotlin library
  • The Gradle plugin
  • The IntelliJ Platform plugin
  • The sample code
  • The documentation

To Reproduce

Related issue in Dagger: google/dagger#3394

java.lang.IllegalStateException: Given component holder class dev.testify.ComposableTestActivity does not implement interface dagger.hilt.internal.GeneratedComponent or interface dagger.hilt.internal.GeneratedComponentManager
	at dagger.hilt.EntryPoints.get(EntryPoints.java:62)
	at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.createInternal(HiltViewModelFactory.java:206)
	at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.createInternal(HiltViewModelFactory.java:200)
	at androidx.hilt.navigation.HiltViewModelFactory.create(HiltNavBackStackEntry.kt:77)
	at androidx.hilt.navigation.compose.HiltViewModelKt.createHiltViewModelFactory(HiltViewModel.kt:57)

Example workaround:
https://github.com/android/nowinandroid/blob/main/ui-test-hilt-manifest/src/main/kotlin/com/google/samples/apps/nowinandroid/uitesthiltmanifest/HiltComponentActivity.kt

@djette-st djette-st added the Bug Any behaviour the deviates from the documentation, expected outcome or API contract. label Feb 26, 2024
@DanielJette DanielJette added the Extension Relates to one of the extension libraries label Feb 26, 2024
@matteo-goghero-leitha
Copy link

I have the same problem too, event the workaround doesn't work.

@DanielJette
Copy link
Contributor

@matteo-goghero-leitha

The bug occurs in Testify because the ComposableTestActivity is automatically launched by the ComposableScreenshotRule

There's an extra step needed to work around this problem:

  1. There needs to be a subclass of ComposableTestActivity that implements ComponentActivity like in https://github.com/android/nowinandroid/blob/main/ui-test-hilt-manifest/src/main/kotlin/com/google/samples/apps/nowinandroid/uitesthiltmanifest/HiltComponentActivity.kt
  2. There also needs to be a subclass of ComposableScreenshotRule which uses the Activity created in the previous step.

So, for now, I think the only way around this in Testify 2.0 would be for you to duplicate the code in ComposableScreenshotRule and create your own version of it that uses a ComponentActivity instead of the hardcoded ComposableTestActivity.

Otherwise, this will have to be fixed in a future version of Testify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any behaviour the deviates from the documentation, expected outcome or API contract. Extension Relates to one of the extension libraries
Projects
None yet
Development

No branches or pull requests

3 participants