escodro

    escodro

    1 year ago
    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!
    ppvi

    ppvi

    1 year ago
    have you tried
    createEmptyComposeRule
    ?
    escodro

    escodro

    1 year ago
    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?
    ppvi

    ppvi

    1 year ago
    yes that's the idea I think but I haven't had the chance to use it, let me know if it works please
    escodro

    escodro

    1 year ago
    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. 😊
    ppvi

    ppvi

    1 year ago
    wait but you're not using the compose test rule at all? you're not going to be able to target compose elements
    escodro

    escodro

    1 year ago
    I’m sorry. The image does not represent the full context.
    @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 { ... }
            }
        }