Closed hoboris closed 1 year ago
Hey @hoboris, this is probably caused by the LaunchedEffect
that is hidden inside the shimmer modifier.
I'm not familiar with Robolectric, but could get it to work by disabling the automatic clock synchronization between the tests and compose UI (Jetpack Documentation - Disable Autosync).
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import androidx.test.core.app.launchActivity
import org.junit.Rule
import org.robolectric.annotation.LooperMode
@RunWith(RobolectricTestRunner::class)
class MainActivityTest {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Test
@LooperMode(LooperMode.Mode.PAUSED)
fun testShimmer() {
composeTestRule.mainClock.autoAdvance = false
launchActivity<MainActivity>().onActivity {
assert(true)
}
}
}
I'm not sure if that is the way to go with Robolectric, but I hope it helps. Let me know if I can close this issue. :)
Hey Valentin! I'm implementing unit tests for my Composables that use your shimmer, but they are not passing within a reasonable time. When
Modifier.shimmer()
is called, unit tests seems to continue running for a while, then eventually finishes after a very long time.Given the following Activity:
And the following test :
The test only passes after more than 2 hours.
But when
//.shimmer()
is commented out, then the test passes as expected after a few seconds.