Hello, everyone! :blush: Is there a way to run re...
# compose
e
Hello, everyone! 😊 Is there a way to run repeat/flaky tests in Jetpack Compose? If I add any rule to do it, it fails with
Cannot call setContent twice per test!
Is it possible to “clearContent” before starting it again? Some of my tests are flaky because I need to mix it up with Espresso. ☹️ Thanks in advance!
p
have you tried
createEmptyComposeRule
?
e
No, I didn’t know that! Thanks a lot! 😊 So basically I use this rule and in each test set the ActivityScenario to launch my Composable?
p
yes that's the idea I think but I haven't had the chance to use it, let me know if it works please
❤️ 1
e
Thanks a lot again, José. It worked! I don’t know if I did the best implementation, but it is working without any issues so far. 😊
p
wait but you're not using the compose test rule at all? you're not going to be able to target compose elements
e
I’m sorry. The image does not represent the full context.
Copy code
@get:Rule
val composeTestRule = createEmptyComposeRule()

@get:Rule
val flakyRule = FlakyTestRule().allowFlakyAttemptsByDefault(defaultAttempts = 10)

private lateinit var scenario: ActivityScenario<ComponentActivity>

@Before
fun setup() {
    scenario = ActivityScenario.launch(ComponentActivity::class.java)
}

@After
fun tearDown(){
    scenario.close()
}

@Test
@Repeat(times = 10)
fun test() {
        scenario.onActivity {
            it.setContent { ... }
        }
    }
138 Views